<p>
Handles HTTP error codes.
</p>

@param responseCode the HTTP response code
@throws FetcherException if response code is in the range 400 to 599 inclusive
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);
        }
    }
750066
protected void throwIfErrorResponse(RESTResponse response) {
        if (response.getCode().isError()) {
            String errMsg = response.getBody();
            if (Utils.isEmpty(errMsg)) {
                errMsg = "Unknown error; response code: " + response.getCode();
            }
            throw new RuntimeException(errMsg);
        }
    }
825168
@Override
    public void sendError(int code, String message) throws IOException {
        if (isCommitted()) {
            throw new IllegalStateException("Response already committed");
        }
        resetBuffer();
        this.response.setStatus(code);
        commit();
        if (null != message) {
            if (null != this.outWriter) {
                this.outWriter.print(message);
            } else {
                this.outStream.print(message);
            }
            flushBuffer();
        }
    }
655368
private void handleErrorResponse(String jsonResponse)
			throws MusixMatchException {
		StatusCode statusCode;
		Gson gson = new Gson();

		System.out.println(jsonResponse);

		ErrorMessage errMessage = gson.fromJson(jsonResponse,
				ErrorMessage.class);
		int responseCode = errMessage.getMessageContainer().getHeader()
				.getStatusCode();

		switch (responseCode) {
		case 400:
			statusCode = StatusCode.BAD_SYNTAX;
			break;
		case 401:
			statusCode = StatusCode.AUTH_FAILED;
			break;
		case 402:
			statusCode = StatusCode.LIMIT_REACHED;
			break;
		case 403:
			statusCode = StatusCode.NOT_AUTHORIZED;
			break;
		case 404:
			statusCode = StatusCode.RESOURCE_NOT_FOUND;
			break;
		case 405:
			statusCode = StatusCode.METHOD_NOT_FOUND;
			break;
		default:
			statusCode = StatusCode.ERROR;
			break;
		}

		throw new MusixMatchException(statusCode.getStatusMessage());
	}
263289
@Override
	public void error(final String code) {
		WMessages instance = getWMessageInstance();

		if (instance != null) {
			instance.error(code);
		}
	}
115141
def _exception_for(self, code):
        
        if code in self.errors:
            return self.errors[code]
        elif 500 <= code < 599:
            return exceptions.RemoteServerError
        else:
            return exceptions.UnknownError
838996
protected void returnJsonSystemError(HttpServletRequest request, HttpServletResponse response,
            ResultCode resultCode) throws IOException {
        Map<String, Object> errors = new HashMap<String, Object>();
        errors.put(WebResponseConstant.MESSAGE_GLOBAL, resultCode.getMessage().getMessage());
        JsonObject<?> json = JsonObject.create();
        json.setStatus(resultCode.getCode());
        json.setStatusInfo(errors);
        response.setContentType("application/json; charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(JsonUtils.toJson(json));
    }
141907
public HTTPResponse handleError(HTTPResponse response) throws HTTPException {
        if (response.statusCode < 200 || response.statusCode >= 300) {
            throw new HTTPException(response.statusCode, response.reason);
        }
        return response;
    }
1162746
@Override
    protected void throwExceptionForError(final int errorCode) {
        try {
            m_connection.throwException(errorCode);
        } catch (final IOException e) {
            throw new RuntimeException(e);
        }
    }
1163367
private void handleErrorCode() {
		String msg = I18nUtilities
				.format(UIContextHolder.getCurrent().getLocale(),
						InternalMessages.DEFAULT_STEP_ERROR);
		throw new ErrorCodeEscape(HttpServletResponse.SC_BAD_REQUEST, msg);
	}
806182
private function validateResult(array $responseArr, $httpCode)
    {
        $httpCode = (int) $httpCode;

        if ($httpCode === 200) {
            // The request is successful - nothing to do
            return;
        }

        $errorMessage = $this->getErrorMessage($responseArr);
        $errorCode = isset($responseArr['code']) ? $responseArr['code'] : 'Error';

        // Throw the error message that's included in the response
        if (!empty($errorMessage)) {
            throw new AmlException("$errorCode - {$errorMessage}", $httpCode);
        }

        // Throw a general error message
        throw new AmlException("{$errorCode} - Server responded with {$httpCode}", $httpCode);
    }
760921
public RequestContext renderCode(final int code) {
        if (renderer instanceof JsonRenderer) {
            final JsonRenderer r = (JsonRenderer) renderer;

            final JSONObject ret = r.getJSONObject();
            ret.put(Keys.CODE, code);
        }

        return this;
    }
1252192
public function setHttpResponseCode($code)
    {
        if (!is_int($code) || (100 > $code) || (599 < $code)) {
            throw new \Exception('Invalid HTTP response code');
        }

        $this->_isRedirect = (300 <= $code) && (307 >= $code);
        $this->_httpResponseCode = $code;
        return $this;
    }
1155960
public static HttpResponseException errorWithoutStack(final int code, final String errorMessage) {
        return new HttpResponseException() {
            public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {
                rsp.sendError(code, errorMessage);
            }
        };
    }
769713
public function onBeforeHTTPError($statusCode, $request)
    {
        if (Director::is_ajax()) {
            return;
        }
        $response = ErrorPage::response_for($statusCode);
        if ($response) {
            throw new HTTPResponse_Exception($response, $statusCode);
        }
    }
1356677
public void setErrorCode(String errorCode) {
		if (errorCode != null) {
			NullArgumentException.validateNotEmpty(errorCode, "Error code");
		}
		this.errorCode = errorCode;
	}
740623
public function iGetAResponseWithAStatusCodeOf($code)
    {
        $actual = $this->getGuzzleResponse()->getStatusCode();

        if ($actual != $code) {
            throw new ClientErrorResponseException(
                'Actual status code ' . $actual . ' does not match expected ' .
                'status code ' . $code . ' with message: ' .
                $this->getGuzzleResponse()->getMessage()
            );
        }
    }