decodeStatusCode static method

String decodeStatusCode(
  1. int statusCode, {
  2. String? defaultMessage,
})

Implementation

static String decodeStatusCode(int statusCode, {String? defaultMessage}) {
  final messages = {
    // Common HTTP status codes
    200: "[OK] - The request was successful.",
    201: "[Created] - A new resource was created.",
    204: "[No Content] - The server has no content to send.",
    301:
        "[Moved Permanently] - The requested resource has been permanently moved to a new location.",
    302:
        "[Found] - The requested resource has been temporarily moved to a new location.",
    400: "[Bad Request] - The request is invalid.",
    401: "[Unauthorized] - The request requires user authentication.",
    403: "[Forbidden] - The server has denied the request.",
    404: "[Not Found] - The requested resource could not be found.",
    405:
        "[Method Not Allowed] - The request method is not supported for this resource.",
    409: "[Conflict] - The request could not be completed due to a conflict.",
    500:
        "[Internal Server Error] - An unexpected error occurred on the server.",
    502:
        "[Bad Gateway] - The server received an invalid response from an upstream server.",
    503: "[Service Unavailable] - The server is currently unavailable.",
  };

  // Check for defined message in the map
  final message = messages[statusCode];

  // Return the mapped message or default message if not found
  return message ?? defaultMessage ?? "Unknown Status Code";
}