API Error Handling
What is API error handling?
API error handling is the way software detects, describes, and responds to failed API requests. A server returns a clear result, and the client app decides what to show or do next.
HTTP API error codes: 400, 404, 429, and 500
Status codes identify the failure category.
| Code | Meaning | Client action |
|---|---|---|
| 2xx | Success | Use the response. |
| 3xx | Redirect | Follow the new location when appropriate. |
| 400 | Invalid request | Correct missing or invalid input. |
| 401 / 403 | Not signed in / not permitted | Authenticate or request access. |
| 404 | Resource not found | Check the endpoint or item ID. |
| 429 | Too many requests | Wait, then retry as directed. |
| 500 / 503 | Server failure / unavailable | Retry cautiously or report it. |
How to handle API errors
- Detect a failed HTTP response or network failure.
- Read the standard error payload.
- Show a plain-language, user-safe message.
- Retry only temporary failures such as 429 or 503.
- Log the request ID and diagnostic context.
- Escalate unexpected failures for investigation.
What a useful API error response includes
Use a consistent schema containing an HTTP status, stable application code, short message, validation details, and request ID. RFC 9457 Problem Details is one optional format. Keep stack traces and secrets in private logs, not user responses.
API error-handling best practices
Reliable APIs make failure states predictable.
- Validate input before processing an API request.
- Document errors in API documentation.
- Return retry guidance, including Retry-After for rate limits.
- Protect credentials during API authentication.
- Test known failure paths and idempotent retries.
Practical limits and common mistakes
Not every API error can be fixed by the client.
- Repeated retries can worsen an overloaded service.
- A generic 500 hides useful diagnosis.
- Stack traces can expose sensitive internals.
- A 200 response with an error body confuses standard tools.
API error handling in Emergent
When building full-stack apps and integrations with Emergent, define and test user-facing failure states alongside successful flows. Build and test API responses with Emergent.
Frequently Asked Questions
Your Questions, Answered
Don't change this element unless you know what you are doing
How do you handle errors in a REST API?
Return the correct HTTP status, a consistent error payload, a safe message, and a request ID. Clients should correct 4xx issues and retry only temporary 429 or 5xx failures.
What do 3xx, 4xx, and 5xx errors mean in HTTP?
3xx means the resource has moved or needs redirection. 4xx means the request, credentials, or permissions need attention. 5xx means the server could not complete a valid request.
What is the difference between a 400 and a 500 API error?
A 400 means the client sent an invalid request, such as missing required input. A 500 means an unexpected server-side problem occurred.
What does a 404 error mean in an API?
A 404 means the requested endpoint or resource was not found. Check the URL, API version, and resource ID.
What is an HTTP 429 error?
A 429 error means the client exceeded a rate limit. Pause requests and follow any Retry-After instruction before trying again.
How should an app handle a 500 internal server error?
Show a friendly fallback message, log the request ID, and avoid immediate repeated retries. Retry later only when the operation is safe to repeat.
on Emergent today


