/*
Error Status

@param response     JSON response object from Lob service
481657
function LobErrorStatus(response) {
  MessagingServiceStatus.call(this, 'lob');

  this.state.message = response.message;

  // See https://lob.com/docs/node#errors for details
  if (response.status_code == 401) this.state.code = this.StatusCodes.UNAUTHORIZED;
  else if (response.status_code == 404) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (response.status_code == 422) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (response.status_code == 500) this.state.code = this.StatusCodes.SERVICE_DOWN;
  else this.state.code = this.StatusCodes.DEFAULT;
}
11486
function serverResponseToRESPONSE (response) {
	try {
		const obj = JSON.parse(response);
		if (obj.result === RESPONSE_UNKNOWN) {
			return RESPONSE_UNKNOWN;
		} else {
			return obj.result.result;
		}
	} catch (e) {
		return RESPONSE_INVALID;
	}
}
1196116
def error_response(self, error, mimetype='application/json', status=400,
            **kwargs):
        
        return HttpResponse(json.dumps(error), mimetype=mimetype,
                status=status, **kwargs)
1288042
public static Mono<Throwable> buildError(ClientResponse response) {
		return Mono.error(new CredHubException(response.statusCode()));
	}
640008
function (error, response) {
        if (!_.isNull(error)) {
            error = _.createError(error);
        } else if (!_.isNull(response) && (response.status >= 400 || response.status === 0)) {
            error = _.createError(null, response);
            response = null;
        }
        callback(error, response);
    }
641090
function NexmoErrorStatus(response) {
  MessagingServiceStatus.call(this, 'nexmo');

  // There was an error when attempting to send message
  this.state.message = response.messages[0].status + ': ' + response.messages[0]['error-text'];

  // See https://docs.nexmo.com/index.php/sms-api/send-message#response_code for details
  var statusCode = parseInt(response.messages[0].status);
  if (statusCode == 1) this.state.code = this.StatusCodes.LIMIT_EXCEEDED;
  else if (statusCode == 2) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (statusCode == 3) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (statusCode == 4) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (statusCode == 5) this.state.code = this.StatusCodes.SERVICE_DOWN;
  else if (statusCode == 6) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (statusCode == 7) this.state.code = this.StatusCodes.UNAUTHORIZED;
  else if (statusCode == 8) this.state.code = this.StatusCodes.UNAUTHORIZED;
  else if (statusCode == 9) this.state.code = this.StatusCodes.LIMIT_EXCEEDED;
  else if (statusCode == 11) this.state.code = this.StatusCodes.UNAUTHORIZED;
  else if (statusCode == 12) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (statusCode == 13) this.state.code = this.StatusCodes.SERVICE_DOWN;
  else if (statusCode == 14) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (statusCode == 15) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (statusCode == 16) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (statusCode == 19) this.state.code = this.StatusCodes.UNAUTHORIZED;
  else if (statusCode == 20) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (statusCode == 29) this.state.code = this.StatusCodes.UNAUTHORIZED;
  else this.state.code = this.StatusCodes.DEFAULT;
}
66996
boolean isErrorResponse(HttpResponse response) {
        StatusLine status = response.getStatusLine();
        if (status == null || status.getStatusCode() != 200) {
            return true;
        }
        return false;
    }
1373002
function internalError(response, message, body) {
  var content = errorContent(ErrorType.server, message, body);
  send(response, content, StatusCode.internalServerError);
}
1298378
function status(response) {
  if (response.status >= 200 && response.status < 300) {
    return Promise.resolve(response);
  }

  return Promise.reject(new Error(response.statusText));
}
419826
function PushBotsErrorStatus(response) {
  MessagingServiceStatus.call(this, 'pushbots');

  // There was an error when attempting to send message
  this.state.message = response.code + ': ' + response.message;

  // See https://pushbots.com/developer/api/1 for details
  if (response.statusCode == 400) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (response.statusCode == 401) this.state.code = this.StatusCodes.UNAUTHORIZED;
  else if (response.statusCode == 405) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (response.statusCode == 409) this.state.code = this.StatusCodes.DATA_REJECTED;
  else if (response.statusCode == 429) this.state.code = this.StatusCodes.LIMIT_EXCEEDED;
  else if (response.statusCode == 507) this.state.code = this.StatusCodes.LIMIT_EXCEEDED;
  else if (response.statusCode >= 500 && response.statusCode < 600) this.state.code = this.StatusCodes.SERVICE_DOWN;
  else this.state.code = this.StatusCodes.DEFAULT;
}
1024926
private void errorStatus(MtasSolrStatus status, IOException exception) {
		try {
			status.setError(exception);
			if (requestHandler != null) {
				requestHandler.finishStatus(status);
			}
		} catch (IOException e) {
			log.error(e);
		}
	}
1111031
public void assertCorrectResonse(JSONObject response) throws JSONException {
		Integer lastHTTPResponseCode = getLastHTTPResponseCode();
		if(lastHTTPResponseCode != null) {
			//if a response code is set, check it. Selenium requests do not let you query this which is why we can't check this in case of a selenium API call
			assertEquals("The https response code should be 200 (OK)", new Integer(HttpURLConnection.HTTP_OK), lastHTTPResponseCode);
		}
		assertNotNull("The request should result in a response", response);	
	}
1063880
protected void handleExceptionIfNeeded(HttpResponse response) throws GloboDnsException, IOException {
		int statusCode = response.getStatusCode();
		if (statusCode/100 == 2) {
			// 200 family code
			// Successful return, do nothing
			return;
		} else if (statusCode/100 == 4 || statusCode/100 == 5) {
			// 400 and 500 family codes
			// Something was wrong, produce an error result
			String responseAsString = response.parseAsString();
			if (responseAsString == null || !responseAsString.startsWith("{")) {
				// Response not well formed!
				throw new GloboDnsHttpException("Unknown error in GloboDNS: " + responseAsString, statusCode);
			}
			
			GloboDnsRoot<ErrorMessage> responseObj = this.parse(responseAsString, ErrorMessage.class);
			ErrorMessage errorMsg = responseObj.getFirstObject();
			if (errorMsg != null && errorMsg.getMsg() != null) {
				throw new GloboDnsHttpException(errorMsg.getMsg(), statusCode);
			} else {
				throw new GloboDnsHttpException(responseAsString, statusCode);
			}
		} else {
			// Unknown error code, return generic exception with description
			throw new GloboDnsHttpException(response.parseAsString(), statusCode);
		}
	}
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);
    }
398820
def json_error_response(error, response, status_code=400):
    
    msg = {"error": error.error, "error_description": error.explanation}

    response.status_code = status_code
    response.add_header("Content-Type", "application/json")
    response.body = json.dumps(msg)

    return response
972635
function (error, response, body) {
            if (error) {
                // Usually means we never got a response - server is down, no DNS entry, etc.
                _endDownload(downloadId, Errors.NO_SERVER_RESPONSE);
                return;
            }
            if (response.statusCode !== 200) {
                _endDownload(downloadId, [Errors.BAD_HTTP_STATUS, response.statusCode]);
                return;
            }

            var stream = temp.createWriteStream("brackets");
            if (!stream) {
                _endDownload(downloadId, Errors.CANNOT_WRITE_TEMP);
                return;
            }
            pendingDownloads[downloadId].localPath = stream.path;
            pendingDownloads[downloadId].outStream = stream;

            stream.write(body);
            _endDownload(downloadId);
        }
352529
function responseStatus(res) {
  if (res.status >= 200 && res.status < 300) {
    return res;
  } else {
    var error = new Error(res.statusText);
    error.response = res;
    throw customError('responseStatus', error);
  }
}