StatusResponse is a simple framework to assist in HTTP Status Response Codes.
pod 'StatusResponse'import StatusResponseSimply pass the status code to the HTTPStatus() function
let status = HTTPStatus(100)
let category = status.statusCategory // .informational
let description = status.statusDescription // Continue
let success = status.isSuccess // Falselet status = HTTPStatus(201)
let category = status.statusCategory // .success
let description = status.statusDescription // OK
let success = status.isSuccess // Truelet status = HTTPStatus(301)
let category = status.statusCategory // .redirection
let description = status.statusDescription // Moved Permanently
let success = status.isSuccess // Falselet status = HTTPStatus(401)
let category = status.statusCategory // .clientError
let description = status.statusDescription // Unauthorized
let success = status.isSuccess // Falselet status = HTTPStatus(500)
let category = status.statusCategory // .serverError
let description = status.statusDescription // Internal Server Error
let success = status.isSuccess // FalseIf you have custom error messages you wish to log or display to the user you can set errorMessages. By default, the default error message is the status description.
let errorMessages = [401: "Your username/password are incorrect", 423: "Your account is locked"]
StatusResponse.setErrorMessages(errorMessages)
let status = HTTPStatus(401)
let error = status.errorMessage // Your username/password are incorrect
let status2 = HTTPStatus(500)
let error2 = status.errorMessage // Internal Server ErrorYou can change the default error message by setting StatusResponse.setDefaultErrorMessage().
let errorMessages = [401: "Your username/password are incorrect", 423: "Your account is locked"]
StatusResponse.setErrorMessages(errorMessages)
StatusResponse.setDefaultErrorMessage("An Unknown Error Occurred")
let status = HTTPStatus(401)
let error = status.errorMessage // Your username/password are incorrect
let status2 = HTTPStatus(500)
let error2 = status.errorMessage // An Unknown Error Occurred