exceptionForStatus function
Builds the exception subtype that matches an HTTP statusCode.
Anything unmapped becomes a ServerException at or above 500, and a plain LiveTennisApiException otherwise.
Implementation
LiveTennisApiException exceptionForStatus(
int statusCode,
String message, {
String? code,
Object? body,
Map<String, String> headers = const {},
String? url,
String? requiredTier,
num? retryAfter,
}) {
switch (statusCode) {
case 400:
return BadRequestException(message,
code: code, body: body, headers: headers, url: url);
case 401:
return UnauthorizedException(message,
code: code, body: body, headers: headers, url: url);
case 403:
return UpgradeRequiredException(message,
code: code,
body: body,
headers: headers,
url: url,
requiredTier: requiredTier);
case 404:
return NotFoundException(message,
code: code, body: body, headers: headers, url: url);
case 429:
return RateLimitedException(message,
code: code,
body: body,
headers: headers,
url: url,
retryAfter: retryAfter);
case 503:
return ServiceUnavailableException(message,
code: code, body: body, headers: headers, url: url);
default:
if (statusCode >= 500) {
return ServerException(message,
statusCode: statusCode,
code: code,
body: body,
headers: headers,
url: url);
}
return LiveTennisApiException(message,
statusCode: statusCode,
code: code,
body: body,
headers: headers,
url: url);
}
}