<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _error_template(cls, status_code, errors, source=None):
 """Construct JSON error response :param status_code: the http status code :param errors: string or list of error strings :param source: source of the error :returns: dictionary, e.g. { 'status': 400, 'errors': [ { 'source': 'accounts' , 'message':'errormsg1' }, { 'source': 'accounts', 'message':'errormsg2' } ] } """

        # this handles unhandled exceptions
        if isinstance(errors, basestring):
            errors_out = {'errors': [{'message': errors}]}
        elif isinstance(errors, (list, tuple)):
            errors_out = {'errors': [{'message': e} for e in errors]}
        else:
            errors_out = errors
        errors_out['status'] = status_code

        for error in errors_out['errors']:
            if not error.get('source'):
                error['source'] = source

        logging.error(json.dumps(errors_out))
        return errors_out