DEV Community

Cover image for Common Status Codes in gRPC and HTTP
Milad Roudgarian
Milad Roudgarian

Posted on

2

Common Status Codes in gRPC and HTTP

HTTP status codes are integral to REST API applications and microservices. With the introduction of the gRPC framework, applications gained the ability to redefine their roles based on traditional protocol/RPC standards.

Effective error handling is crucial, prompting the need to convert gRPC status codes into their HTTP equivalents for seamless processing by REST API services. The table below outlines the corresponding status codes, enhancing the development workflow. For more in-depth information, refer to the gRPC-GateWay repository.

|-----------------------------|---------------------------|
| gRPC Status Code            | HTTP Status Code          |
|-----------------------------|---------------------------|
|`OK` (Code: 0)               | 200 OK                    |
|`CANCELLED` (Code: 1)        | 499 Client Closed Request |
|`UNKNOWN` (Code: 2)          | 500 Internal Server Error |
|`INVALID_ARGUMENT` (Code: 3) | 400 Bad Request           |
|`DEADLINE_EXCEEDED` (Code: 4)| 504 Gateway Timeout       |
|`NOT_FOUND` (Code: 5)        | 404 Not Found             |
|`ALREADY_EXISTS` (Code: 6)   | 409 Conflict              |
|`PERMISSION_DENIED` (Code: 7)| 403 Forbidden             |
|`RESOURCE_EXHAUSTED`(Code:8) | 429 Too Many Requests     |
|`FAILED_PRECONDITION`(Code:9)| 400 Bad Request           |
|`ABORTED` (Code: 10)         | 409 Conflict              |
|`OUT_OF_RANGE` (Code: 11)    | 400 Bad Request           |
|`UNIMPLEMENTED` (Code: 12)   | 501 Not Implemented       |
|`INTERNAL` (Code: 13)        | 500 Internal Server Error |
|`UNAVAILABLE` (Code: 14)     | 503 Service Unavailable   |
|`DATA_LOSS` (Code: 15)       | 500 Internal Server Error |
|-----------------------------|---------------------------|
Enter fullscreen mode Exit fullscreen mode

Note that some gRPC status codes may not have a direct HTTP equivalent, and the mappings are based on best-fit scenarios. Additionally, gRPC status codes provide more granular information about the status of a request compared to HTTP status codes.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs