handleErrorStatusCode method

void handleErrorStatusCode(
  1. HttpResponse response
)

Implementation

void handleErrorStatusCode(HttpResponse response) {
  switch (response.statusCode) {
    case HttpStatus.UNAUTHORIZED:
    case HttpStatus.NOT_FOUND:
      throw InvalidCredentials(
        "Make sure your credentials from 'todo.json' are correct and valid.",
      );
    case HttpStatus.SERVICE_UNAVAILABLE:
      throw ServiceUnavaiable(
        "Service unavaiable. Please try again later. \n\nMessage from API: ${response.body['message']}",
      );
    case HttpStatus.UNPROCESSABLE_ENTITY:
      throw SpammedCommand(
        "Validation failed or this command was probably spammed. \n\nMessage from API: ${response.body['message']}",
      );
    default:
      // TODO(hicaro): improving error reporting for this case
      throw UnexpectedError(response.body.toString());
  }
}