Formats a 404 error when an endpoint or file wasn't found
<p>
<b>WARNING:</b> If overriding, make sure this method catches all errors and
returns a byte array with a simple string error at the minimum
@return A standard JSON error
543486
public ChannelBuffer formatNotFoundV1() {
    StringBuilder output = 
      new StringBuilder(1024);
    if (query.hasQueryStringParam("jsonp")) {
      output.append(query.getQueryStringParam("jsonp") + "(");
    }
    output.append("{\"error\":{\"code\":");
    output.append(404);
    output.append(",\"message\":\"");
    if (query.apiVersion() > 0) {
      output.append("Endpoint not found");
    } else {
      output.append("Page not found");
    }
    output.append("\"}}");
    if (query.hasQueryStringParam("jsonp")) {
      output.append(")");
    }
    return ChannelBuffers.copiedBuffer(
        output.toString().getBytes(this.query.getCharset()));
  }
211040
public static function getJSONErrorAsString()
	{
		switch(json_last_error())
		{
			case JSON_ERROR_NONE:
				$error =  NULL;
			break;
			
			case JSON_ERROR_DEPTH:
				$error = 'The maximum stack depth has been exceeded.';
			break;
				
			case JSON_ERROR_STATE_MISMATCH:
				$error = 'Invalid or malformed JSON.';
			break;

			case JSON_ERROR_CTRL_CHAR:
				$error = 'Control character error, possibly incorrectly encoded.';
			break;

			case JSON_ERROR_SYNTAX:
				$error = 'Syntax error, malformed JSON.';
			break;

			// PHP >= 5.3.3
			case JSON_ERROR_UTF8:
				$error = 'Malformed UTF-8 characters, possibly incorrectly encoded.';
			break;

			// PHP >= 5.5.0
			case JSON_ERROR_RECURSION:
				$error = 'One or more recursive references in the value to be encoded.';
			break;

			// PHP >= 5.5.0
			case JSON_ERROR_INF_OR_NAN:
				$error = 'One or more NAN or INF values in the value to be encoded.';
			break;

			case JSON_ERROR_UNSUPPORTED_TYPE:
				$error = 'A value of a type that cannot be encoded was given.';
			break;

			default:
				$error = NULL;
			break;
		}
		
		return $error;
	}
691044
public static <T extends Errors> T parseErrorResponse(ObjectMapper mapper, ResponseBody errorResponse, Class<T> cls) throws IOException {
        return mapper.readValue(errorResponse.bytes(), cls);
    }
718271
def error(self, status_code, request, message=None):
        
        status_code_text = HTTP_STATUS_CODES.get(status_code, 'http error')
        status_error_tag = status_code_text.lower().replace(' ', '_')
        custom_response_map = {
            404: self.make_error_response(
                status_error_tag,
                'The requested URL {} was not found on this service.'.format(
                    request.path
                )
            ),
            400: self.make_error_response(status_error_tag, message),
            405: self.make_error_response(
                status_error_tag,
                'The requested URL {} was not allowed HTTP method {}.'.format(
                    request.path, request.method
                )
            ),
        }
        return self._raw_response(
            status_code,
            custom_response_map.get(
                status_code,
                self.make_error_response(
                    status_error_tag, message or status_code_text
                )
            )
        )
536434
public static JsonObjectBase buildFieldError(Map<String, String> errors, ErrorCode statusCode) {

        JsonObjectError json = new JsonObjectError();
        json.setStatus(statusCode.getCode());

        for (String str : errors.keySet()) {
            json.addFieldError(str, contextReader.getMessage(errors.get(str)));
        }

        LOG.info(json.toString());

        return json;
    }
981953
public com.google.api.ads.adwords.axis.v201809.rm.OfflineDataUploadErrorReason getReason() {
        return reason;
    }
1100723
@GET
    @Path("/warnings")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getVariantsWithWarnings(@Context HttpServletRequest request) {
        final List<ApplicationVariant> variantsWithWarnings = service.getSearchService().getVariantsWithWarnings();

        return Response.ok(variantsWithWarnings).build();
    }
861309
protected static String getString(List<Error> errorList) {
		String exceptionDetails = "";
		if (errorList != null) {
			Iterator<Error> iter = errorList.iterator();
			while (iter.hasNext()) {
				Error error = iter.next();
				StringBuilder sb = new StringBuilder();
				sb.append("ERROR CODE:").append(error.getCode()).append(", ERROR MESSAGE:").append(error.getMessage()).append(", ERROR DETAIL:")
						.append(error.getDetail());
				/**
				 * this was done as a result of adding Payment APIs; this wasn't
				 * done before. so keep it consistent with V3 SDK (to preserve
				 * the behaviour for V3) the null check is being done before adding it.
				 */
				if (error.getElement() != null) {
					sb.append(", MORE ERROR DETAIL:").append(error.getElement());
				}
				sb.append("\r\n");
				exceptionDetails = exceptionDetails + sb.toString();
			}
		}
		return exceptionDetails;
	}
1201306
@Override
  public void notFound() {
    logWarn("Not Found: " + request().getUri());
    if (this.api_version > 0) {
      // always default to the latest version of the error formatter since we
      // need to return something
      switch (this.api_version) {
        case 1:
        default:
          sendReply(HttpResponseStatus.NOT_FOUND, serializer.formatNotFoundV1());
      }
      return;
    }
    if (hasQueryStringParam("json")) {
      sendReply(HttpResponseStatus.NOT_FOUND,
                new StringBuilder("{\"err\":\"Page Not Found\"}"));
    } else {
      sendReply(HttpResponseStatus.NOT_FOUND, PAGE_NOT_FOUND);
    }
  }
757359
@SuppressWarnings("unchecked")
    protected JsonObject paramError(Map<String, Object> errors) {
        JsonObject json = JsonObject.create();
        json.setStatus(GlobalResponseStatusMsg.SYSTEM_ERROR.getMessage().getCode());
        Map<String, Object> error = new HashMap<String, Object>();
        error.put(WebResponseConstant.MESSAGE_FIELD, errors);
        json.setStatusInfo(error);
        return json;
    }
504714
public static String getError(final HttpServletRequest request) {
		StringBuilder sb = (StringBuilder) request.getAttribute(ERROR_KEY);
		if (sb == null) {
			return "";
		}
		return sb.toString();
	}
124011
@com.fasterxml.jackson.annotation.JsonProperty("ErrorDetails")
    public java.util.List<ErrorDetail> getErrorDetails() {
        return errorDetails;
    }
1042146
private JSONObject errorForUnwrappedException(Exception e, JmxRequest pJmxReq) {
        Throwable cause = e.getCause();
        int code = cause instanceof IllegalArgumentException ? 400 : cause instanceof SecurityException ? 403 : 500;
        return getErrorJSON(code,cause, pJmxReq);
    }
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)
1123299
private void sendErrorJSON(HttpServletResponse response, int statusCode, String errorCode, String errorDescription) {
        final String error = "error";
        final String error_description = "error_description";
        try {
            if (errorCode != null) {
                response.setStatus(statusCode);
                response.setHeader(ClientConstants.REQ_CONTENT_TYPE_NAME,
                        "application/json;charset=UTF-8");

                JSONObject responseJSON = new JSONObject();
                responseJSON.put(error, errorCode);
                if (errorDescription != null) {
                    responseJSON.put(error_description, errorDescription);
                }
                PrintWriter pw;
                pw = response.getWriter();
                pw.write(responseJSON.toString());
                pw.flush();
            } else {
                response.sendError(statusCode);
            }
        } catch (IOException e) {
            if (tc.isDebugEnabled())
                Tr.debug(tc, "Internal error sending error message", e);
            try {
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            } catch (IOException ioe) {
                if (tc.isDebugEnabled())
                    Tr.debug(tc, "yet another internal error, give up", ioe);
            }
        }

    }
551676
public JSONObject getRawDataAsJson() throws IOException
    {
        String input = getRawDataAsString();
        if ( input == null ) {
            return null;
        }
        
        return new JSONObject(input);
    }
858908
public static String createErrorMessage(HttpException exception) {
    String json = tryParseAsJsonError(exception.content());
    if (json != null) {
      return json;
    }

    String msg = "HTTP code " + exception.code();
    if (isHtml(exception.content())) {
      return msg;
    }

    return msg + ": " + StringUtils.left(exception.content(), MAX_ERROR_MSG_LEN);
  }