4_http_status_code
Opinionated Stance on HTTP Status Codes
There is no official mapping of JSON-RPC error codes to HTTP status codes in the JSON-RPC 2.0 specification. JSON-RPC 2.0 is transport-agnostic and does not mandate any particular use of HTTP status codes.
PATH takes an opinionated stance on mapping JSON-RPC errors to HTTP status codes. This is a common practice but not an industry standard.
JSON-RPC to HTTP Status Code Mapping
It's common practice in JSON-RPC-over-HTTP implementations to map:
Client errors (e.g., -32600
Invalid Request) to 4xx HTTP statusesServer errors (e.g., -32603
Internal erroror -32000 "Server error") to 5xx HTTP statuses
PATH follows this practice and maps JSON-RPC errors to HTTP status codes as follows:
-32700
Parse error
400 Bad Request
-32600
Invalid request
400 Bad Request
-32601
Method not found
404 Not Found
-32602
Invalid params
400 Bad Request
-32603
Internal error
500 Server Error
-32098
Timeout
504 Gateway Timeout
-32097
Rate limited
429 Too Many Requests
-32000…-32099
Server error range
500 Server Error
> 0
Application errors (client-side)
400 Bad Request
< 0 (other negative)
Application errors (server-side)
500 Server Error
Status Code Implementation
PATH implements this mapping in the Response.GetRecommendedHTTPStatusCode() method:
References
Was this helpful?
