Converts the exception to a user-presentable error message. Specifically,
extracts message field for HTTP 4xx codes, and creates a generic
"Internal Server Error" for HTTP 5xx codes.
975036
public String toUserPresentableMessage(IOException ioe, @Nullable String action) {
    String message = "Internal server error";
    if (isClientError(ioe)) {
      message = getErrorMessage(ioe);
    }

    if (action == null) {
      return message;
    } else {
      return String.format("Encountered an error while %s: %s", action, message);
    }
  }
479361
def process_exception_message(exception):
        
        exception_message = str(exception)
        for replace_char in ['\t', '\n', '\\n']:
            exception_message = exception_message.replace(replace_char, '' if replace_char != '\t' else ' ')
        return exception_message.replace('section', 'alias')
1270852
def _http_error_handler(http_error):
    ''' '''
    message = str(http_error)
    error_code = None

    if 'x-ms-error-code' in http_error.respheader:
        error_code = http_error.respheader['x-ms-error-code']
        message += ' ErrorCode: ' + error_code

    if http_error.respbody is not None:
        message += '\n' + http_error.respbody.decode('utf-8-sig')

    ex = AzureHttpError(message, http_error.status)
    ex.error_code = error_code

    raise ex
662835
def http_error(self, url, fp, errcode, errmsg, headers, data=None):
        """"""
        # First check if there's a specific handler for this error
        name = 'http_error_%d' % errcode
        if hasattr(self, name):
            method = getattr(self, name)
            if data is None:
                result = method(url, fp, errcode, errmsg, headers)
            else:
                result = method(url, fp, errcode, errmsg, headers, data)
            if result: return result
        return self.http_error_default(url, fp, errcode, errmsg, headers)
728263
def from_http_exception(cls, e):
        """"""
        assert isinstance(e, requests.exceptions.HTTPError)
        response = e.response
        try:
            message = response.json()['message']
        except (KeyError, ValueError):
            message = response.content.strip()

        raise cls(message)
1069181
def handleException(exception):
    
    serverException = exception
    if not isinstance(exception, exceptions.BaseServerException):
        with app.test_request_context():
            app.log_exception(exception)
        serverException = exceptions.getServerError(exception)
    error = serverException.toProtocolElement()
    # If the exception is being viewed by a web browser, we can render a nicer
    # view.
    if flask.request and 'Accept' in flask.request.headers and \
            flask.request.headers['Accept'].find('text/html') != -1:
        message = "<h1>Error {}</h1><pre>{}</pre>".format(
                    serverException.httpStatus,
                    protocol.toJson(error))
        if serverException.httpStatus == 401 \
                or serverException.httpStatus == 403:
            message += "Please try <a href=\"/login\">logging in</a>."
        return message
    else:
        responseStr = protocol.toJson(error)
        return getFlaskResponse(responseStr, serverException.httpStatus)
1266830
def map_http_status_to_exception(http_code):
        
        http_exceptions = HttpError.__subclasses__()
        for http_exception in http_exceptions:
            http_statuses = http_exception.HTTP_STATUSES
            if isinstance(http_statuses, int):
                http_statuses = [http_exception.HTTP_STATUSES]

            try:
                if http_code in http_statuses:
                    return http_exception
            except TypeError:  # Pass if statuses is not iterable (≈ None)
                pass

        return HttpError
136563
def generate_error_message(tag, err_uniq, err_appl, err_mult):
    
    err = []
    if err_uniq:
        err.append('Uniqueness restriction: item type %s' % tag.item_type)
    if err_appl:
        err.append('Applicability restriction: field %s' % tag.field)
    if err_mult:
        err.append('Multiplicity restriction: field %s' % tag.field)
    return err
280843
def server_error(request, template_name="errors/500.html"):
    
    context = {"STATIC_URL": settings.STATIC_URL}
    t = get_template(template_name)
    return HttpResponseServerError(t.render(context, request))
337244
def validation_error(exception):
    """"""
    messages = getattr(exception, 'messages', None)
    if messages is None:
        messages = getattr(exception, 'data', {'messages': None})['messages']

    def extract_errors():
        """Extract errors from exception."""
        if isinstance(messages, dict):
            for field, message in messages.items():
                if field == 'verb':
                    yield 'badVerb', '\n'.join(message)
                else:
                    yield 'badArgument', '\n'.join(message)
        else:
            for field in exception.field_names:
                if field == 'verb':
                    yield 'badVerb', '\n'.join(messages)
                else:
                    yield 'badArgument', '\n'.join(messages)

            if not exception.field_names:
                yield 'badArgument', '\n'.join(messages)

    return (etree.tostring(xml.error(extract_errors())),
            422,
            {'Content-Type': 'text/xml'})
170508
def _ReraiseTypeErrorWithFieldName(message_name, field_name):
  """"""
  exc = sys.exc_info()[1]
  if len(exc.args) == 1 and type(exc) is TypeError:
    # simple TypeError; add field name to exception message
    exc = TypeError('%s for field %s.%s' % (str(exc), message_name, field_name))

  # re-raise possibly-amended exception with original traceback:
  six.reraise(type(exc), exc, sys.exc_info()[2])
81846
def format_error(err_type, err_value, err_trace=None):
    """"""
    if err_trace is None:
        err_parts = "".join(traceback.format_exception_only(err_type, err_value)).strip().split(": ", 1)
        if len(err_parts) == 1:
            err_name, err_msg = err_parts[0], ""
        else:
            err_name, err_msg = err_parts
        err_name = err_name.split(".")[-1]
        return err_name + ": " + err_msg
    else:
        return "".join(traceback.format_exception(err_type, err_value, err_trace)).strip()
1195380
def parse_error(self, exception=ParseError, *args):
        
        return self._src.parse_error(exception, *args)
66522
def create_api_error_from_http_exception(e):
    
    response = e.response
    try:
        explanation = response.json()['message']
    except ValueError:
        explanation = (response.content or '').strip()
    cls = APIError
    if response.status_code == 404:
        if explanation and ('No such image' in str(explanation) or
                            'not found: does not exist or no pull access'
                            in str(explanation) or
                            'repository does not exist' in str(explanation)):
            cls = ImageNotFound
        else:
            cls = NotFound
    raise cls(e, response=response, explanation=explanation)
558815
static void processError(String type, String errString, HttpServerExchange exchange) {
        exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR);
        exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, CONTENT_TYPE);
        exchange.getResponseHeaders().add(new HttpString("Version"), VERSION_PROTOCOL);
        exchange.getResponseHeaders().add(new HttpString("Type"), type);
        exchange.getResponseHeaders().add(new HttpString("Mess"), errString);
        exchange.endExchange();
        UndertowLogger.ROOT_LOGGER.mcmpProcessingError(type, errString);
    }
1241016
public InternalFieldErrorBuilder createFieldConversionError(final String field, final Class<?> fieldType, final Object rejectedValue) {
        
        final String fieldPath = buildFieldPath(field);
        final String[] codes = messageCodeGenerator.generateTypeMismatchCodes(getObjectName(), fieldPath, fieldType);
        
        return new InternalFieldErrorBuilder(this, getObjectName(), fieldPath, codes)
                .sheetName(getSheetName())
                .rejectedValue(rejectedValue)
                .conversionFailure(true);
        
        
    }
1247217
protected StatusObject generateErrorResult(String code, Throwable error) {
        // Construct error object to return
        String message = "";
        while (error != null && error.getCause() != null) {
            error = error.getCause();
        }
        if (error != null && error.getMessage() != null) {
            message = error.getMessage();
        }
        StatusObject status = new StatusObject(code, "error", message);
        if (error instanceof ClientDetailsException) {
            // Return exception details to client
            status.setApplication(((ClientDetailsException) error).getParameters());
            if (((ClientDetailsException) error).includeStacktrace()) {
                List<String> stack = new ArrayList<String>();
                for (StackTraceElement element : error.getStackTrace()) {
                    stack.add(element.toString());
                }
                status.setAdditional("stacktrace", stack);
            }
        } else if (error != null) {
            status.setApplication(error.getClass().getCanonicalName());
            List<String> stack = new ArrayList<String>();
            for (StackTraceElement element : error.getStackTrace()) {
                stack.add(element.toString());
            }
            status.setAdditional("stacktrace", stack);
        }
        return status;
    }