Skip to main content

Get started

Error Handling Best Practices

When integrating with Shell APIs, proper error handling ensures reliability and a smooth user experience. Below are the recommended practices:

Standard HTTP Status Codes

  • 2xx – Success
  • 4xx – Client errors (e.g., invalid input)
  • 5xx – Server errors (retryable)

Error Response Structure

Typical error response:

{
  "RequestId": "eb621f45-a543-4d9a-a934-2f223b263c42",
  "Status": "FAILED",
  "Errors": [
     {
        "Code": "E0001",
        "Detail": "Invalid parameter value for AddressLine1",
        "Title": "Validation Error",
        "AdditionalInfo": {
          "addressLine1": "John Marks street ?"
        }
     }
  ]
}

Error Code Reference

Code Title Description HTTP Code
E0001 Validation Error Returned when parameter fails business validations like not null, etc. 400
E0002 Unknown Error Returned when unhandled exceptions are encountered 500
E0003 Unauthorized Returned when invalid credentials (client id, secret, API key) are passed 401
E0004 Timeout Error Returned when timeout(s) are encountered while processing the request 408
E0005 Not Found Returned when target endpoint is not available 404
E0006 Forbidden Returned when an unauthorized request is received 403
E0007 Method Not Allowed Returned when the request endpoint or method is not available 405
E0008 Too Many Requests Returned when requests per minute exceed the allowed/configured policy 429
E0009 Unsupported Media Type Returned when unsupported payload media type is received 415
E0010 Payload Too Large Returned when the received payload size exceeds the permissible limit 413
E0011 Bad Request Returned when unsupported payload format is received 400
E0012 Connectivity Error Returned when a connectivity failure is encountered (e.g., DB connection) 503
E0013 Retry Exhausted Error Returned when max number of retries are completed 503
E0014 Partial Success Returned when the requested operation is partially successful 200
E0015 URI Too Long The URI requested by the client is longer than the server can interpret 414
E0016 Bad Gateway As a gateway, received an invalid response needed to handle the request 502

Retry Logic

  • Retry only on 5xx errors or network timeouts
  • Use exponential backoff (e.g., 1s, 2s, 4s)
  • Do not retry on 4xx errors; fix the request instead

Rate Limiting

  • If you receive 429 Too Many Requests, respect the Retry-After header before retrying

Logging & Monitoring

  • Always log RequestId for troubleshooting
  • Mask sensitive data (tokens, credentials) in logs

Request ID Guidelines

  • Use a requestId in UUID v4 format (e.g., 123e4567-e89b-12d3-a456-426614174000) for every request
  • Helps with log correlation, debugging, and tracing across services
  • Generate once at the entry point and propagate downstream

Example Error Scenarios

  • Invalid Payload: Ensure JSON structure matches API spec
  • Authentication Failure: Refresh token and retry
  • Quota Exceeded: Implement usage monitoring and alerts

Additional Information

  • Additional Info: Some error scenarios include additional information in the error payload under the AdditionalInfo section. Look for this section to investigate more details about the error.

About us

The Shell Developer Portal supports partners in onboarding to Shell APIs and turning ideas into production-ready solutions.

 

Shell logo

Login to your account