for bad response, whose responseCode is not 200 level

@param responseCode
@param errorCode
@param errorMsg
@return
@throws JSONException
427516
public static JSONObject processGoodRespStr(int responseCode, String goodRespStr) throws JSONException {
        JSONObject response = new JSONObject();
        response.put("responseCode", responseCode);
        if (goodRespStr.equalsIgnoreCase("")) {
            response.put("responseMsg", "");
        } else {
            response.put("responseMsg", new JSONObject(goodRespStr));
        }

        return response;
    }
1252404
public static <T extends CharSequence> T validateLetter(T value, String errorMsg) throws ValidateException {
		if (false == isLetter(value)) {
			throw new ValidateException(errorMsg);
		}
		return value;
	}
318677
public static void sendError(int errorCode, String errorContent) {
		HttpServletResponse response = Response.getServletResponse();
		try {
			if(HuluSetting.isDevMode) {
				response.sendError(errorCode);
			}else {
				response.sendError(errorCode, errorContent);
			}
		} catch (IOException e) {
			log.error(e, "Error when sendError!");
		}
	}
142991
static public ExceptionItems parseException(int code, String json) {
        ExceptionItems items = new ExceptionItems();
        
        items.code = code;
        items.type = CloudErrorType.GENERAL;
        items.message = "unknown";
        items.details = "The cloud returned an error code with explanation: ";
        if (items.code == HttpStatus.SC_UNAUTHORIZED) {
            items.type = CloudErrorType.AUTHENTICATION;
        }
        if( json != null ) {
            try {
                JSONObject ob = new JSONObject(json);

                if( code == 400 && ob.has("badRequest") ) {
                    ob = ob.getJSONObject("badRequest");
                }
                if( code == 413 && ob.has("overLimit") ) {
                    ob = ob.getJSONObject("overLimit");
                }
                if( ob.has("message") ) {
                    items.message = ob.getString("message");
                    if( items.message == null ) {
                        items.message = "unknown";
                    }
                    else {
                        items.message = items.message.trim();
                    }
                }
                if (items.message.equals("unknown")) {
                    String[] names = JSONObject.getNames(ob);
                    for (String key : names) {
                        try {
                            JSONObject msg = ob.getJSONObject(key);
                            if (msg.has("message") && !msg.isNull("message")) {
                                items.message = msg.getString("message");
                            }
                        }
                        catch (JSONException e) {
                            items.message = ob.getString(key);
                        }
                    }
                }
                if( ob.has("details") ) {
                    items.details = items.details + ob.getString("details");
                }
                else {
                    items.details = items.details + "[" + code + "] " + items.message;
                }
                String t = items.message.toLowerCase().trim();

                if( code == 413 ) {
                    items.type = CloudErrorType.THROTTLING;
                }
                else if( t.startsWith("addresslimitexceeded") || t.startsWith("ramlimitexceeded")) {
                    items.type = CloudErrorType.QUOTA;
                }
                else if( t.equals("unauthorized") ) {
                    items.type = CloudErrorType.AUTHENTICATION;
                }
                else if( t.equals("serviceunavailable") ) {
                    items.type = CloudErrorType.CAPACITY;
                }
                else if( t.equals("badrequest") || t.equals("badmediatype") || t.equals("badmethod") || t.equals("notimplemented") ) {
                    items.type = CloudErrorType.COMMUNICATION;
                }
                else if( t.equals("overlimit") ) {
                    items.type = CloudErrorType.QUOTA;
                }
                else if( t.equals("servercapacityunavailable") ) {
                    items.type = CloudErrorType.CAPACITY;
                }
                else if( t.equals("itemnotfound") ) {
                    return null;
                }
            }
            catch( JSONException e ) {
                NovaOpenStack.getLogger(NovaException.class, "std").warn("parseException(): Invalid JSON in cloud response: " + json);
                items.details = items.details+" "+json;
            }
        }
        return items;
    }
898262
private static JSONObject genError(Integer code, String message) throws JSONException {
        // TODO: HTTP-Status (404, etc), for now return status line
        return new JSONObject("{error: {code: \"" + code.toString() + "\", message: \"" + message + "\"}}");
    }
1162746
@Override
    protected void throwExceptionForError(final int errorCode) {
        try {
            m_connection.throwException(errorCode);
        } catch (final IOException e) {
            throw new RuntimeException(e);
        }
    }
994197
private JsonRpcClientException createJsonRpcClientException(ObjectNode errorObject) {
		int code = errorObject.has(JsonRpcBasicServer.ERROR_CODE) ? errorObject.get(JsonRpcBasicServer.ERROR_CODE).asInt() : 0;
		return new JsonRpcClientException(code, errorObject.get(JsonRpcBasicServer.ERROR_MESSAGE).asText(), errorObject.get(JsonRpcBasicServer.DATA));
	}
1084416
def json_error(code, message):
    """"""
    # Message can be an unserializable object.
    message = repr(message)
    return jsonify(dict(request=request.path, message=message)), code
928983
protected function jsonErrorResponse($errorMessage, $statusCode = 400, array $httpHeaders = array())
    {
        $statusTexts = \Symfony\Component\HttpFoundation\Response::$statusTexts;

        return $this->jsonResponse(array(
            'error' => (string) $errorMessage,
        ), array(
            'status' => array(
                'code'    => (int) $statusCode,
                'message' => $statusTexts[$statusCode],
            ),
        ), $httpHeaders);
    }
526353
protected MultiValueMap<String, Object> buildResponseEntityErrorModel(final HttpStatus code, final String message) {
        return CollectionUtils.asMultiValueMap("code",
            code.value(),
            "message", message);
    }
41836
public function response_json($code, $msg, $data, $http_num = 200)
    {

        return response()->json([
            'error' => $code,
            'msg' => $msg,
            'data' => $data,
        ], $http_num);
    }
932845
public static OAuth2Exception create(String errorCode, String errorMessage) {
		if (errorMessage == null) {
			errorMessage = errorCode == null ? "OAuth Error" : errorCode;
		}
		if (INVALID_CLIENT.equals(errorCode)) {
			return new InvalidClientException(errorMessage);
		}
		else if (UNAUTHORIZED_CLIENT.equals(errorCode)) {
			return new UnauthorizedClientException(errorMessage);
		}
		else if (INVALID_GRANT.equals(errorCode)) {
			return new InvalidGrantException(errorMessage);
		}
		else if (INVALID_SCOPE.equals(errorCode)) {
			return new InvalidScopeException(errorMessage);
		}
		else if (INVALID_TOKEN.equals(errorCode)) {
			return new InvalidTokenException(errorMessage);
		}
		else if (INVALID_REQUEST.equals(errorCode)) {
			return new InvalidRequestException(errorMessage);
		}
		else if (REDIRECT_URI_MISMATCH.equals(errorCode)) {
			return new RedirectMismatchException(errorMessage);
		}
		else if (UNSUPPORTED_GRANT_TYPE.equals(errorCode)) {
			return new UnsupportedGrantTypeException(errorMessage);
		}
		else if (UNSUPPORTED_RESPONSE_TYPE.equals(errorCode)) {
			return new UnsupportedResponseTypeException(errorMessage);
		}
		else if (ACCESS_DENIED.equals(errorCode)) {
			return new UserDeniedAuthorizationException(errorMessage);
		}
		else {
			return new OAuth2Exception(errorMessage);
		}
	}
977063
protected void handleErrorCodes(final int responseCode) throws FetcherException {
        // Handle 2xx codes as OK, so ignore them here
        // 3xx codes are handled by the HttpURLConnection class
        if (responseCode == 403) {
            // Authentication is required
            throwAuthenticationError(responseCode);
        } else if (responseCode >= 400 && responseCode < 500) {
            throw4XXError(responseCode);
        } else if (responseCode >= 500 && responseCode < 600) {
            throw new FetcherException(responseCode, "The server encounted an error. HTTP Response code was:" + responseCode);
        }
    }
1278390
function writeError(code, res, msg) {
	try{
		if (res.headerSent) {
			logger.error("header Sent:", res.req.method, res.req.originalUrl);
		}
		if (httpCodeMapping) {
			code = mapHttpStatusCode(code);
		}
		msg = msg instanceof Error ? msg.message : msg;
		addStrictTransportHeaders(res);
		setResponseNoCache(res);
		if (typeof msg === 'string') {
			var err = JSON.stringify({Severity: "Error", Message: msg});
			res.setHeader('Content-Type', 'application/json');
			res.setHeader('Content-Length', err.length);
			res.writeHead(code);
			res.end(err);
		} else {
			res.writeHead(code);
			res.end();
		}
	}catch(err){
		logger.error(res.req.originalUrl , err.message);
		throw err;
	}
}
81650
public void reject(final String errorCode, final Map<String, Object> messageVariables) {
        reject(errorCode, messageVariables, null);
    }
1056481
public MAPErrorMessage createMessageFromErrorCode(Long errorCode) {
        long ec = (long) errorCode;
        switch ((int) ec) {
            case MAPErrorCode.unexpectedDataValue:
            case MAPErrorCode.dataMissing:
            case MAPErrorCode.unidentifiedSubscriber:
            case MAPErrorCode.illegalSubscriber:
            case MAPErrorCode.illegalEquipment:
            case MAPErrorCode.teleserviceNotProvisioned:
            case MAPErrorCode.messageWaitingListFull:
            case MAPErrorCode.unauthorizedRequestingNetwork:
            case MAPErrorCode.resourceLimitation:
            case MAPErrorCode.unknownOrUnreachableLCSClient:
            case MAPErrorCode.incompatibleTerminal:
            case MAPErrorCode.noRoamingNumberAvailable:
            case MAPErrorCode.noSubscriberReply:
            case MAPErrorCode.forwardingFailed:
            case MAPErrorCode.orNotAllowed:
            case MAPErrorCode.forwardingViolation:
            case MAPErrorCode.numberChanged:
            case MAPErrorCode.unknownMSC:
            case MAPErrorCode.unknownEquipment:
            case MAPErrorCode.bearerServiceNotProvisioned:
            case MAPErrorCode.mmEventNotSupported:
            case MAPErrorCode.illegalSSOperation:
            case MAPErrorCode.ssNotAvailable:
            case MAPErrorCode.ssSubscriptionViolation:
            case MAPErrorCode.unknownAlphabet:
            case MAPErrorCode.ussdBusy:
            case MAPErrorCode.negativePWCheck:
            case MAPErrorCode.numberOfPWAttemptsViolation:
            case MAPErrorCode.shortTermDenial:
            case MAPErrorCode.longTermDenial:
                return new MAPErrorMessageExtensionContainerImpl(errorCode);

            case MAPErrorCode.smDeliveryFailure:
                return new MAPErrorMessageSMDeliveryFailureImpl();

            case MAPErrorCode.absentSubscriberSM:
                return new MAPErrorMessageAbsentSubscriberSMImpl();

            case MAPErrorCode.systemFailure:
                return new MAPErrorMessageSystemFailureImpl();

            case MAPErrorCode.callBarred:
                return new MAPErrorMessageCallBarredImpl();

            case MAPErrorCode.facilityNotSupported:
                return new MAPErrorMessageFacilityNotSupImpl();

            case MAPErrorCode.unknownSubscriber:
                return new MAPErrorMessageUnknownSubscriberImpl();

            case MAPErrorCode.subscriberBusyForMTSMS:
                return new MAPErrorMessageSubscriberBusyForMtSmsImpl();

            case MAPErrorCode.absentSubscriber:
                return new MAPErrorMessageAbsentSubscriberImpl();

            case MAPErrorCode.unauthorizedLCSClient:
                return new MAPErrorMessageUnauthorizedLCSClientImpl();

            case MAPErrorCode.positionMethodFailure:
                return new MAPErrorMessagePositionMethodFailureImpl();

            case MAPErrorCode.busySubscriber:
                return new MAPErrorMessageBusySubscriberImpl();

            case MAPErrorCode.cugReject:
                return new MAPErrorMessageCUGRejectImpl();

            case MAPErrorCode.roamingNotAllowed:
                return new MAPErrorMessageRoamingNotAllowedImpl();

            case MAPErrorCode.ssErrorStatus:
                return new MAPErrorMessageSsErrorStatusImpl();

            case MAPErrorCode.ssIncompatibility:
                return new MAPErrorMessageSsIncompatibilityImpl();

            case MAPErrorCode.pwRegistrationFailure:
                return new MAPErrorMessagePwRegistrationFailureImpl();

            default:
                return new MAPErrorMessageParameterlessImpl(errorCode);
        }

    }
1175903
private JsonNode processErrorResponse(final JsonNode resp) {
        String errorMessage = resp.get("error").asText();
        if (resp.has("stack")) {
            errorMessage += "\n" + resp.get("stack").asText();
        }

        throw new JsiiException(errorMessage);
    }