Default error handler.
     - On server side error shows a message
       'An error occurred!' and returns 500 status code.
     - Also serves well in the case when the resource/task/method
       is not found - returns 404 status code.
556531
def error_handler(f):
    

    @wraps(f)
    def error_handling_function(*args, **kwargs):
        @inject(error_config=ErrorConfiguration)
        def get_error_configuration(error_config):
            # type:(ErrorConfiguration)->ErrorConfiguration
            return error_config

        def should_skip_handling():
            use_flask_handler = get_error_configuration().use_flask_handler
            is_web_request = isinstance(JobContext.get_current_context(), WebJobContext)
            return use_flask_handler and is_web_request

        try:
            return f(*args, **kwargs)
        except Exception as ex:
            if should_skip_handling():
                raise

            for ep in _error_processors:
                ep.handle(ex)

            for eh in _error_handlers:
                if eh.can_handle(ex):
                    return eh.handle(ex)

            return _DEFAULT_ERROR_HANDLER.handle(ex)

    return error_handling_function
1248544
function _onError (err) {
  if (err.status === 404 || err.statusCode === 404 || err.expose) return

  let msg = err.stack || err.toString()

  console.error(`\n${msg.replace(/^/gm, '   ')}\n`)
}
1158898
function defaultErrorHandler(jqXHR, textStatus, errorThrown) {
    var result = {
        status: REQUEST_FAIL_STATUS,
        statusInfo: {
            message: '服务器正忙...请稍后再试',
            detail: {
                httpStatus: jqXHR.status,
                textStatus: textStatus,
                errorThrown: errorThrown,
                xhr: jqXHR
            }
        }
    };

    commonErrorStatusHandler.call(this, result);
    return $.Deferred().reject(result).promise();
}
1320332
def json_error_handler(exception):
    
    http_exception = isinstance(exception, exceptions.HTTPException)
    code = exception.code if http_exception else 500

    # log exceptions only (app debug should be off)
    if code == 500:
        current_app.logger.error(exception)

    response = jsonify(dict(message=str(exception)))
    response.status_code = code
    return response
1326823
function onError( error ) {
		debug( 'Error encountered while querying endpoint: %s', error.message );
		if ( error instanceof Error ) {
			err = {
				'status': 500,
				'message': 'Request error: ' + error.message
			};
			return clbk( err );
		}
		return clbk( error, res, body );
	}
1130939
def handle_error(self, error, req, schema, error_status_code, error_headers):
        
        status_code = error_status_code or self.DEFAULT_VALIDATION_STATUS
        if status_code == 422:
            reason = "Unprocessable Entity"
        else:
            reason = None
        raise HTTPError(
            status_code,
            log_message=str(error.messages),
            reason=reason,
            messages=error.messages,
            headers=error_headers,
        )
815056
function error(status, msg) {
  var err = new Error(msg);
  err.status = status;
  return err;
}
1343528
def retryable_http_error( e ):
    
    if isinstance( e, urllib.error.HTTPError ) and e.code in ('503', '408', '500'):
        # The server returned one of:
        # 503 Service Unavailable
        # 408 Request Timeout
        # 500 Internal Server Error
        return True
    if isinstance( e, BadStatusLine ):
        # The server didn't return a valid response at all
        return True
    return False
1197588
def http_error_307(self, url, fp, errcode, errmsg, headers, data=None):
        """"""
        if data is None:
            return self.http_error_302(url, fp, errcode, errmsg, headers, data)
        else:
            return self.http_error_default(url, fp, errcode, errmsg, headers)
1010907
function serverError(err, res) {
  // error is required to be logged
  log('error', err.message, { stack: err.stack });

  const message = err.message || 'Server Error', // completely hide these messages from outside
    code = 500;

  sendDefaultResponseForCode(code, message, res);
}
1197290
def default_errorhandler(self, f):
        
        for http_code in default_exceptions:
            self.error_handler_spec[None][http_code] = f
        return f
629235
def handle_404(request, exception):
    '''
    '''
    error = format_error(title='Resource not found', detail=str(exception))
    return json(return_an_error(error), status=HTTPStatus.NOT_FOUND)
255367
function handlePreResponseError(server) {
        server.ext('onPreResponse', function (request, reply) {
            var response = request.response;
            var originalResponse = response;
            var msg;

            // No error, keep going with the reply as normal
            if (!response.isBoom) { reply.continue(); return; }

            // we need to convert to AppError if it is not already
            if (!(response instanceof AppError)) {
                msg = response.message || (response + '');

                // if legit 404 be sure to use that code (happens with not found in /dist on local)
                if (msg.indexOf('404:') >= 0 ||
                    (response.output && response.output.payload &&
                    response.output.payload.statusCode === 404)) {

                    response = new AppError({
                        code: 'not_found',
                        msg: 'The resource ' + request.url.path + ' was not found'
                    });
                }
                else {
                    msg = response.message || (response + '');
                    if (response.data) { msg += ' : ' + response.data; }

                    log.info(msg);

                    response = new AppError({
                        code: response.code || 'api_error',
                        msg: msg,
                        err: response
                    });
                }
            }

            var code = response.code || 'unknown_error';
            var err = errorDecoder[code] || errorDecoder['unknown_error'];
            var url = request.path;

            if (err.httpErrorCode === 404) {
                trackingService.pageNotFound({
                    caller: request.caller,
                    url: routeHelper.getBaseUrl(request.app.name) + url
                });
            }
            else {
                log.error(request.method + ' ' + url + ' (' + err.friendlyMessage + ')',
                    { err: originalResponse }   );
            }

            //TODO: this hack sucks, but needed quick way to display error page; do better!
            if (pancakes.getContainer() === 'webserver') {

                // hack fix for issue when error on trust site
                if (request.app && request.app.name === 'trust') {
                    reply().redirect(routeHelper.getBaseUrl('contact') + '?notify=loginFailure');
                }
                // else show error pages
                else {
                    var errUrl = err.httpErrorCode === 404 ? '/error404' : '/error500';
                    pancakes.processRoute({ request: request, reply: reply, urlOverride: errUrl, returnCode: err.httpErrorCode });
                }
            }
            else {
                reply(Boom.create(err.httpErrorCode, err.friendlyMessage));
            }
        });
    }
657217
def httperror_handler(error):
    
    status_code = error.status_code or 500
    output = {
        'code': status_code,
        'message': error.body or UNEXPECTED_ERROR,
        'reason': bottle.HTTP_CODES.get(status_code) or None,
    }
    if bottle.DEBUG:
        LOG.warning("Debug-mode server is returning traceback and error "
                    "details in the response with a %s status.",
                    error.status_code)
        if error.exception:
            output['exception'] = repr(error.exception)
        else:
            if any(sys.exc_info()):
                output['exception'] = repr(sys.exc_info()[1])
            else:
                output['exception'] = None

        if error.traceback:
            output['traceback'] = error.traceback
        else:
            if any(sys.exc_info()):
                # Otherwise, format_exc() returns "None\n"
                # which is pretty silly.
                output['traceback'] = traceback.format_exc()
            else:
                output['traceback'] = None

    # overwrite previous body attr with json
    if isinstance(output['message'], bytes):
        output['message'] = output['message'].decode(
            'utf-8', errors='replace')

    # Default type and writer to json.
    accept = bottle.request.get_header('accept') or 'application/json'
    writer = functools.partial(
        json.dumps, sort_keys=True, indent=4)
    error.set_header('Content-Type', 'application/json')
    if 'json' not in accept:
        if 'yaml' in accept:
            if not yaml:
                LOG.warning("Yaml requested but pyyaml is not installed.")
            else:
                error.set_header('Content-Type', 'application/x-yaml')
                writer = functools.partial(
                    yaml.safe_dump,
                    default_flow_style=False,
                    indent=4)
            # html could be added here.

    error.body = [writer(output).encode('utf8')]
    return error.body
731202
def raise_error(self, status=500, message="Generic server error.  Out of luck..."):
        
        self.set_status(status)
        self.write({"message" : message,
                    "status" : status})
1332098
def _defaultErrorHandler(varBinds, **context):
        """"""
        errors = context.get('errors')

        if errors:
            err = errors[-1]
            raise err['error']
439830
def response(self, request, exception):
        
        handler = self.lookup(exception)
        response = None
        try:
            if handler:
                response = handler(request=request, exception=exception)
            if response is None:
                response = self.default(request=request, exception=exception)
        except Exception:
            self.log(format_exc())
            if self.debug:
                url = getattr(request, 'url', 'unknown')
                response_message = (
                    'Exception raised in exception handler "{}" '
                    'for uri: "{}"\n{}').format(
                        handler.__name__, url, format_exc())
                self._log.error(response_message)
                return text(response_message, 500)
            else:
                return text('An error occurred while handling an error', 500)
        return response