You might encounter errors while using DotHost’s API. These errors are:

Error Codes

Understanding error codes is essential for managing requests and debugging issues in your application. Below are some common error codes categorized by their type.

1. Client Errors (4xx)

These errors indicate problems with the client request.

Example: 400 BAD_REQUEST

{
	"statusCode": 400,
	"statusType": "BAD_REQUEST",
	"message": ["email must be an email"],
	"timestamp": "2024-11-10T12:45:48.772Z",
	"path": "/auth/signup"
}
  • Explanation: The client request was malformed. In this case, the email provided was not in a valid format.

Example: 302 FOUND

{
	"statusCode": 302,
	"statusType": "FOUND",
	"message": "User already exists",
	"timestamp": "2024-11-10T12:47:26.808Z",
	"path": "/auth/signup"
}
  • Explanation: The request cannot be processed because the user already exists in the system. This is a redirect status, indicating that the action cannot be completed, and the user should take a different action (e.g., log in instead of signing up).

2. Server Errors (5xx)

These errors indicate issues on the server-side.

Example: 500 INTERNAL_SERVER_ERROR

{
	"statusCode": 500,
	"statusType": "INTERNAL_SERVER_ERROR",
	"message": "An unexpected error occurred",
	"timestamp": "2024-11-10T13:10:58.120Z",
	"path": "/api/data"
}
  • Explanation: The server encountered an unexpected condition that prevented it from fulfilling the request. This usually requires server-side troubleshooting.

Example: 502 BAD_GATEWAY

{
	"statusCode": 502,
	"statusType": "BAD_GATEWAY",
	"message": "The server received an invalid response from the upstream server",
	"timestamp": "2024-11-10T13:15:30.320Z",
	"path": "/api/external-service"
}
  • Explanation: The server was acting as a gateway or proxy and received an invalid response from an upstream server.

3. Redirection Errors (3xx)

These errors indicate that the client should take additional actions to complete the request.

Example: 302 FOUND

{
	"statusCode": 302,
	"statusType": "FOUND",
	"message": "User already exists",
	"timestamp": "2024-11-10T12:47:26.808Z",
	"path": "/auth/signup"
}
  • Explanation: A 302 FOUND response means the user already exists, and the system is redirecting the client to a new action, such as logging in instead of signing up.

4. Success Codes (2xx)

These codes indicate successful requests.

Example: 200 OK

{
	"statusCode": 200,
	"statusType": "OK",
	"message": "Request was successful",
	"timestamp": "2024-11-10T13:30:00.000Z",
	"path": "/api/data"
}
  • Explanation: A 200 OK response means that the request was successfully processed and the requested data is included in the response.

General Error Handling Tips:

  • Client Errors (4xx): These usually require you to verify and correct your request data. Ensure that your inputs are valid.
  • Server Errors (5xx): These indicate issues on the server side. You might need to contact support or wait for the issue to be resolved.
  • Redirection Errors (3xx): These responses typically require you to take further action, like redirecting the user to a different page.
  • Success Codes (2xx): These confirm that the request was successfully processed.
Handling errors properly ensures better user experience and smoother application performance. Always validate input and implement error handling to respond to different status codes effectively.