voxeraTokenFailure function
The error a failed token request throws: VoxeraBannedException, VoxeraRateLimitedException and VoxeraServiceNotAvailableException for the refusals apps handle by type, a VoxeraTokenException otherwise. Each carries the engine's code.
Implementation
VoxeraError voxeraTokenFailure(DioException e) {
final error = VoxeraError.from(e);
final status = e.response?.statusCode;
final code = error.code;
if (code == VoxeraErrorCode.userBanned ||
// Engines before the error table sent a bare 403 for a ban.
(code == VoxeraErrorCode.forbidden &&
error.message.toLowerCase().contains('ban'))) {
return VoxeraBannedException(error.message, status ?? 403, error.requestId);
}
if (status == 429) {
return VoxeraRateLimitedException(
error.message,
error.retryAfter,
code.httpStatus == 429 ? code : VoxeraErrorCode.rateLimited,
error.requestId,
);
}
if (_notAvailable.contains(code) || status == 403) {
return VoxeraServiceNotAvailableException(
error.message,
status ?? 403,
// A bare 403 from an older engine was the service not being enabled.
code == VoxeraErrorCode.forbidden
? VoxeraErrorCode.serviceNotEnabled
: code,
error.requestId,
);
}
return VoxeraTokenException(
error.message,
statusCode: status,
code: code,
requestId: error.requestId,
retryable: error.retryable,
cause: e,
);
}