Mock 404 Not Found Error Response
Generate a structured 404 Not Found JSON error response with a resource identifier. Useful for testing empty states and error boundaries.
Detailed Explanation
404 Not Found
A 404 response indicates that the requested resource does not exist. This is different from a 400 (bad input) or 403 (forbidden). The mock generates a clean error structure that includes the ID of the missing resource.
Response Structure
{
"error": {
"code": "NOT_FOUND",
"message": "Resource with ID 'a1b2c3d4-...' was not found.",
"details": []
}
}
When to Return 404
GET /api/users/:idwhere the ID does not existPUT /api/users/:idattempting to update a non-existent recordDELETE /api/users/:idwhen the resource has already been deleted- Accessing a nested resource where the parent does not exist
404 vs 410 Gone
Use 404 Not Found when the resource may never have existed or you do not want to reveal that information. Use 410 Gone when you can confirm the resource existed previously but has been permanently deleted.
Frontend Handling
Your UI should display a meaningful empty state or redirect when encountering a 404:
- Show a "not found" illustration with a link back to the list view
- Log the error for debugging
- Avoid showing raw JSON to end users
Security Consideration
Be careful not to leak information in 404 messages. Saying "User with email john@example.com not found" reveals that the email is not registered, which can be exploited for account enumeration attacks.
Use Case
Test your application's empty state UI, error boundaries, and redirect logic by simulating a 404 response from the API when a user navigates to a deleted or non-existent resource.