codeForHTTPStatus function

String codeForHTTPStatus(
  1. int status
)

Takes an HTTP status code and returns the corresponding ErrorCode. This is the standard HTTP status code -> error mapping defined in: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto

Implementation

String codeForHTTPStatus(int status) {
  switch (status) {
    case 0:
      // This can happen if the server returns 500.
      return 'internal';
    case 400:
      return 'invalid-argument';
    case 401:
      return 'unauthenticated';
    case 403:
      return 'permission-denied';
    case 404:
      return 'not-found';
    case 409:
      return 'aborted';
    case 429:
      return 'resource-exhausted';
    case 499:
      return 'cancelled';
    case 500:
      return 'internal';
    case 501:
      return 'unimplemented';
    case 503:
      return 'unavailable';
    case 504:
      return 'deadline-exceeded';
    default:
      return 'unknown';
  }
}