0% found this document useful (0 votes)
23 views2 pages

HTTP Error Codes and User Flow Guide

The document outlines common HTTP error codes and their meanings, such as 200 OK for successful requests and 404 Not Found for missing resources. It also provides best practices for using these error codes in user flows during signup, login, OTP generation, and verification, along with example Express.js responses for each scenario. Key errors include 400 Bad Request for invalid input and 500 Internal Server Error for server issues.

Uploaded by

worela2750
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

HTTP Error Codes and User Flow Guide

The document outlines common HTTP error codes and their meanings, such as 200 OK for successful requests and 404 Not Found for missing resources. It also provides best practices for using these error codes in user flows during signup, login, OTP generation, and verification, along with example Express.js responses for each scenario. Key errors include 400 Bad Request for invalid input and 500 Internal Server Error for server issues.

Uploaded by

worela2750
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Common HTTP Error Codes and Example Responses

• 200 OK: Request succeeded


• 400 Bad Request: Client sent invalid data
• 401 Unauthorized: Authentication required or failed
• 403 Forbidden: Client not allowed to access resource
• 404 Not Found: Resource not found
• 409 Conflict: Conflict with current resource state
• 500 Internal Server Error: Unexpected server error

Best Practices for Using Error Codes in User Flows

Signup:
- 400 Bad Request → Missing fields like email/password.
- 409 Conflict → Email already registered.
- 500 Internal Server Error → Unexpected DB or hashing error.
Login:
- 400 Bad Request → Missing email/password.
- 401 Unauthorized → Wrong credentials.
- 500 Internal Server Error → Unexpected DB error.
OTP Generation:
- 400 Bad Request → Email missing/invalid.
- 200 OK → OTP sent successfully.
- 500 Internal Server Error → Email service failure.
OTP Verification:
- 400 Bad Request → OTP input missing.
- 401 Unauthorized → OTP incorrect or expired.
- 200 OK → OTP verified, user authenticated.
- 500 Internal Server Error → Unexpected hashing/DB error.
Protected Routes:
- 401 Unauthorized → No token provided or invalid.
- 403 Forbidden → User authenticated but not authorized for this resource.

-
Example [Link] Responses

[Link](200).json({ success: true, message: "OTP sent" })


[Link](400).json({ success: false, errorCode: "INVALID_INPUT",
message: "Email is required" });
[Link](401).json({ success: false, errorCode: "INVALID_OTP",
message: "OTP is incorrect" });
[Link](403).json({ success: false, errorCode: "FORBIDDEN",
message: "You are not allowed to perform this action" });
[Link](404).json({ success: false, errorCode: "NOT_FOUND",
message: "User not found" });
[Link](409).json({ success: false, errorCode: "USER_EXISTS",
message: "User already registered" });
[Link](500).json({ success: false, errorCode: "SERVER_ERROR",
message: "Something went wrong on the server" });

You might also like