Gets the json error output according to ODataException.

@param exception ODataException
@return errorJsonResponse
@throws ODataRenderException If unable to render the json error message
322839
public String getJsonError(ODataException exception) throws ODataRenderException {
        checkNotNull(exception);

        LOG.debug("Start building Json error document");

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        try {
            JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(outputStream, JsonEncoding.UTF8);
            jsonGenerator.writeStartObject();

            jsonGenerator.writeObjectFieldStart(ERROR);

            jsonGenerator.writeStringField(CODE, String.valueOf(exception.getCode().getCode()));
            jsonGenerator.writeStringField(MESSAGE, String.valueOf(exception.getMessage()));
            // optional
            if (exception.getTarget() != null) {
                jsonGenerator.writeStringField(TARGET, String.valueOf(exception.getTarget()).replace("\"", "'"));
            }
            jsonGenerator.writeEndObject();
            jsonGenerator.close();

            return outputStream.toString();
        } catch (IOException e) {
            LOG.error("Not possible to write error JSON.");
            throw new ODataRenderException("Not possible to write error JSON: ", e);
        }
    }
686449
protected JsonError handleJsonNodeRequest(final JsonNode node, final OutputStream output) throws IOException {
		if (node.isArray()) {
			return handleArray(ArrayNode.class.cast(node), output);
		}
		if (node.isObject()) {
			return handleObject(ObjectNode.class.cast(node), output);
		}
		return this.writeAndFlushValueError(output, this.createResponseError(VERSION, NULL, JsonError.INVALID_REQUEST));
	}
1156468
public function jsonResponse(Exception $exception)
    {
        $this->exception = $exception;
        $this->jsonApiResponse = new JsonApiResponse;

        if ($this->exceptionIsTreated()) {
            $this->callExceptionHandler();
        } else {
            $this->setDefaultResponse();
        }

        return response()->json(
            $this->jsonApiResponse->toArray(),
            $this->jsonApiResponse->getStatus()
        );
    }
822523
def jsonify_error(message_or_exception, status_code=400):
    """"""
    if isinstance(message_or_exception, Exception):
        message = '%s: %s' % (
            message_or_exception.__class__.__name__, message_or_exception)
    else:
        message = message_or_exception

    logging.debug('Returning status=%s, error message: %s',
                  status_code, message)
    response = jsonify(error=message)
    response.status_code = status_code
    return response
756827
protected function renderJsonErrorMessage(Exception $exception)
    {
        $error = [
            'message' => 'Slim Application Error',
        ];

        if ($this->displayErrorDetails) {
            $error['exception'] = [];

            do {
                $error['exception'][] = [
                    'type' => get_class($exception),
                    'code' => $exception->getCode(),
                    'message' => $exception->getMessage(),
                    'file' => $exception->getFile(),
                    'line' => $exception->getLine(),
                    'trace' => explode("\n", $exception->getTraceAsString()),
                ];
            } while ($exception = $exception->getPrevious());
        }

        return json_encode($error, JSON_PRETTY_PRINT);
    }
893394
@Description("Decodes json to an exception and throws it")
    @ScalarFunction(value = "fail", hidden = true)
    @SqlType("unknown")
    public static boolean failWithException(@SqlType(StandardTypes.JSON) Slice failureInfoSlice)
    {
        FailureInfo failureInfo = JSON_CODEC.fromJson(failureInfoSlice.getBytes());
        // wrap the failure in a new exception to append the current stack trace
        throw new PrestoException(StandardErrorCode.GENERIC_USER_ERROR, failureInfo.toException());
    }
723380
public static <T extends Errors> T parseError(ObjectMapper mapper, JsonNode errorResponse, Class<T> cls) throws JsonProcessingException {
        return mapper.treeToValue(errorResponse, cls);
    }
721217
public static RESTHandlerJsonException createRESTHandlerJsonException(Throwable e, JSONConverter converter, int status) {
        try {
            //See if we need to fetch a converter
            if (converter == null) {
                converter = JSONConverter.getConverter();
            }
            //Create a new OutputStream to avoid any corrupted data
            ByteArrayOutputStream os = new ByteArrayOutputStream();

            //Write the exception inside the output stream
            converter.writeThrowable(os, e);

            //Get the message from the output stream
            String exceptionMessage = os.toString("UTF-8");

            //return a Web exception with the new response
            return new RESTHandlerJsonException(exceptionMessage, status, true);

        } catch (IOException innerException) {
            //Since we got an exception while converting the error just write the actual exception text with an internal error code. This should never
            //happen because our JSONErrorOutputStream shouldn't ever throw an IOException
            return new RESTHandlerJsonException(e.getMessage(), status, true);

        } finally {
            JSONConverter.returnConverter(converter);
        }
    }
737002
public static CrashReport fromJson(String json) throws IllegalArgumentException {
    try {
      return new CrashReport(json);
    } catch (JSONException je) {
      throw new IllegalArgumentException(je.toString());
    }
  }
890971
public HttpResponseHandler<SdkBaseException> createErrorResponseHandler(
            JsonErrorResponseMetadata errorResponsMetadata) {
        return new ApiGatewayErrorResponseHandler(
                createErrorUnmarshallers(errorResponsMetadata.getErrorShapes().stream()),
                SdkStructuredPlainJsonFactory.JSON_FACTORY);
    }
506578
protected function errorResponse(\Exception $exception)
    {
        $error = $this->config->get('datatables.error');
        $debug = $this->config->get('app.debug');

        if ($error === 'throw' || (! $error && ! $debug)) {
            throw new Exception($exception->getMessage(), $code = 0, $exception);
        }

        $this->getLogger()->error($exception);

        return new JsonResponse([
            'draw'            => (int) $this->request->input('draw'),
            'recordsTotal'    => $this->totalRecords,
            'recordsFiltered' => 0,
            'data'            => [],
            'error'           => $error ? __($error) : "Exception Message:\n\n".$exception->getMessage(),
        ]);
    }
1017449
private boolean isJsonProcessingException(Exception e) {
        // Unfortunately Jackson doesn't have specific subclasses for each parse exception, so we have to use the
        // more brittle approach of checking the exception message.
        return e instanceof JsonProcessingException &&
                !(e instanceof JsonParseException &&
                    e.getMessage() != null &&
                    e.getMessage().startsWith("Unexpected end-of-input"));
    }
806141
protected JsonObject sysError() {
        JsonObject json = JsonObject.create();
        json.setStatus(GlobalResponseStatusMsg.SYSTEM_ERROR.getMessage().getCode());
        json.addStatusInfo(GlobalResponseStatusMsg.SYSTEM_ERROR.getMessage().getMessage());
        return json;
    }
1373127
function _treatBadRequestExceptions(responseJSON = {}, options) {
    responseJSON.type = responseJSON.type || errorTypes.entity;
    if (responseJSON.type !== undefined) {
        switch (responseJSON.type) {
            case errorTypes.entity:
                return _treatEntityExceptions(responseJSON, options);
            case errorTypes.collection:
                return _treatCollectionExceptions(responseJSON, options);
            default:
                break;
        }
    }
    return null;
}
1308474
private JsonError handleObject(final ObjectNode node, final OutputStream output) throws IOException {
		logger.debug("Request: {}", node);
		
		if (!isValidRequest(node)) {
			return writeAndFlushValueError(output, createResponseError(VERSION, NULL, JsonError.INVALID_REQUEST));
		}
		Object id = parseId(node.get(ID));
		
		String jsonRpc = hasNonNullData(node, JSONRPC) ? node.get(JSONRPC).asText() : VERSION;
		if (!hasNonNullData(node, METHOD)) {
			return writeAndFlushValueError(output, createResponseError(jsonRpc, id, JsonError.METHOD_NOT_FOUND));
		}

		final String fullMethodName = node.get(METHOD).asText();
		final String partialMethodName = getMethodName(fullMethodName);
		final String serviceName = getServiceName(fullMethodName);
		
		Set<Method> methods = findCandidateMethods(getHandlerInterfaces(serviceName), partialMethodName);
		if (methods.isEmpty()) {
			return writeAndFlushValueError(output, createResponseError(jsonRpc, id, JsonError.METHOD_NOT_FOUND));
		}
		AMethodWithItsArgs methodArgs = findBestMethodByParamsNode(methods, node.get(PARAMS));
		if (methodArgs == null) {
			return writeAndFlushValueError(output, createResponseError(jsonRpc, id, JsonError.METHOD_PARAMS_INVALID));
		}
		try (InvokeListenerHandler handler = new InvokeListenerHandler(methodArgs, invocationListener)) {
			try {
				if (this.requestInterceptor != null) {
					this.requestInterceptor.interceptRequest(node);
				}
				Object target = getHandler(serviceName);
				// interceptors preHandle
				for (JsonRpcInterceptor interceptor : interceptorList) {
					interceptor.preHandle(target, methodArgs.method, methodArgs.arguments);
				}
				// invocation
				JsonNode result = invoke(target, methodArgs.method, methodArgs.arguments);
				handler.result = result;
				// interceptors postHandle
				for (JsonRpcInterceptor interceptor : interceptorList) {
					interceptor.postHandle(target, methodArgs.method, methodArgs.arguments, result);
				}
				if (!isNotificationRequest(id)) {
					ObjectNode response = createResponseSuccess(jsonRpc, id, handler.result);
					writeAndFlushValue(output, response);
				}
				return JsonError.OK;
			} catch (Throwable e) {
				handler.error = e;
				return handleError(output, id, jsonRpc, methodArgs, e);
			}
		}
	}
713230
private Map<String, Object> extractErrorDetailsFromResponse(ClientHttpResponse response) throws IOException {
		ObjectMapper mapper = new ObjectMapper(new JsonFactory());
		try {
			return mapper.<Map<String, Object>> readValue(response.getBody(), new TypeReference<Map<String, Object>>() {
			});
		} catch (JsonParseException e) {
			return null;
		}
	}
79746
private static function extractErrorDescription($exception)
    {
        $json = Client::responseToArray(
            $exception->getResponse()
        );
        if (isset($json['error_description'])) {
            return $json['error_description'];
        } elseif (isset($json['message'])) {
            return $json['message'];
        } else {
            return null;
        }
    }