fetchApiResponseStatusCode static method
Interprets HTTP status codes and returns a descriptive log message.
Maps common HTTP status codes to human-readable descriptions and formats them into a standardized logging message. Useful for API response debugging.
Supported status codes:
- 200: Successful
- 400: Bad request
- 401: Unauthorized: Access denied
- 403: Forbidden: Authentication Failed
- 404: Page not found
- 405: Method not found
- 412: Token expired
- 444: Check your internet connection
- 500: Internal Server Error
- Others: Unknown Status
Parameters:
statusCode: The HTTP status code to interpretapiName: Name of the API endpoint (for logging)apiType: Type of API call (e.g., "GET", "POST")
Returns a formatted log message:
"RT apiType API Response is having status code : {code}: {description}"
Example:
final message = RtCommonFunction.fetchApiResponseStatusCode(401, 'login', 'POST');
// Returns: "RT [login][POST] API Response is having status code : 401: Unauthorized: Access denied"
Implementation
static String fetchApiResponseStatusCode(
int statusCode, String apiName, String apiType) {
String detail;
switch (statusCode) {
case 200:
detail = "Successful";
break;
case 400:
detail = "Bad request";
case 401:
detail = "Unauthorized: Access denied";
break;
case 403:
detail = "Forbidden: Authentication Failed";
break;
case 404:
detail = "Page not found";
break;
case 405:
detail = "Method not found";
break;
case 412:
detail = "Token expired";
break;
case 444:
detail = "Check your internet connection";
break;
case 500:
detail = "Internal Server Error";
break;
default:
detail = "Unknown Status";
}
return "RT [$apiName][$apiType] API Response is having status code : $statusCode: $detail";
}