findError static method
Finds an error message from the response based on the status code and object type.
If the status code is 401
or 403
and the object is a list of bytes or a string,
it attempts to decode the error message.
Returns: A decoded error message if applicable, otherwise null
.
Implementation
static String? findError(
{Object? object, required int statusCode, List<int>? allowStatusCode}) {
String? error;
if (object is List<int>) {
error = StringUtils.tryDecode(object);
} else if (object is String) {
error = object;
}
if (allowStatusCode != null && allowStatusCode.contains(statusCode)) {
return error;
} else if (statusCode == 401 || statusCode == 403) {
return error;
}
return null;
}