mirror of https://github.com/grpc/grpc-java.git
Change the HTTP code -> GRPC Status mapping to comply with http canonical mapping
------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=80767939
This commit is contained in:
parent
c5e70c2310
commit
4332c2f56e
|
@ -32,26 +32,51 @@ public final class HttpUtil {
|
|||
public static Status httpStatusToGrpcStatus(int httpStatusCode) {
|
||||
// Specific HTTP code handling.
|
||||
switch (httpStatusCode) {
|
||||
case HttpURLConnection.HTTP_UNAUTHORIZED: // 401
|
||||
case HttpURLConnection.HTTP_BAD_REQUEST: // 400
|
||||
return Status.INVALID_ARGUMENT;
|
||||
case HttpURLConnection.HTTP_UNAUTHORIZED: // 401
|
||||
return Status.UNAUTHENTICATED;
|
||||
case HttpURLConnection.HTTP_FORBIDDEN: // 403
|
||||
case HttpURLConnection.HTTP_FORBIDDEN: // 403
|
||||
return Status.PERMISSION_DENIED;
|
||||
default:
|
||||
case HttpURLConnection.HTTP_NOT_FOUND: // 404
|
||||
return Status.NOT_FOUND;
|
||||
case HttpURLConnection.HTTP_CONFLICT: // 409
|
||||
return Status.ABORTED;
|
||||
case 416: // Requested range not satisfiable
|
||||
return Status.OUT_OF_RANGE;
|
||||
case 429: // Too many requests
|
||||
return Status.RESOURCE_EXHAUSTED;
|
||||
case 499: // Client closed request
|
||||
return Status.CANCELLED;
|
||||
case HttpURLConnection.HTTP_NOT_IMPLEMENTED: // 501
|
||||
return Status.UNIMPLEMENTED;
|
||||
case HttpURLConnection.HTTP_UNAVAILABLE: // 503
|
||||
return Status.UNAVAILABLE;
|
||||
case HttpURLConnection.HTTP_GATEWAY_TIMEOUT: // 504
|
||||
return Status.DEADLINE_EXCEEDED;
|
||||
}
|
||||
// Generic HTTP code handling.
|
||||
if (httpStatusCode < 200) {
|
||||
// 1xx and below
|
||||
return Status.UNKNOWN;
|
||||
}
|
||||
if (httpStatusCode < 300) {
|
||||
// 2xx
|
||||
return Status.OK;
|
||||
}
|
||||
if (httpStatusCode < 400) {
|
||||
return Status.UNAVAILABLE;
|
||||
// 3xx
|
||||
return Status.UNKNOWN;
|
||||
}
|
||||
if (httpStatusCode < 500) {
|
||||
return Status.INVALID_ARGUMENT;
|
||||
}
|
||||
if (httpStatusCode < 600) {
|
||||
// 4xx
|
||||
return Status.FAILED_PRECONDITION;
|
||||
}
|
||||
return Status.INTERNAL;
|
||||
if (httpStatusCode < 600) {
|
||||
// 5xx
|
||||
return Status.INTERNAL;
|
||||
}
|
||||
return Status.UNKNOWN;
|
||||
}
|
||||
|
||||
private HttpUtil() {}
|
||||
|
|
Loading…
Reference in New Issue