PBharose / Hospital-Management-System

Assignment for learning NodeJS
MIT License
0 stars 0 forks source link

HTTP Status codes and standard responses #6

Closed PBharose closed 1 year ago

PBharose commented 1 year ago

Discussed in https://github.com/PBharose/NodeJS-Assignment/discussions/5

Originally posted by **PBharose** March 10, 2023 # HTTP Status codes and standard responses | Response Code | Description | | ----------- | ----------- | | 200 (Ok) | Request has been successfully processed | | 201 (Created) | Request has been successful and a new resource has been created | | 202 (Accepted) | The request has been accepted, but the processing has not been completed | | 400 (Bad Request) | Invalid request supplied | | 401 (Unauthorized) | Authentication has either failed or not been supplied | | 403 (Forbidden) | Authorization to the requested resource has failed | | 404 (Not Found) | The request resource could not be found | | 500 (Internal Server Error) | An unexpected error occurred | ### Error responses should follow the following standard: ```json { "errorCode": "Unique error code: e.g. P2M0001", "errorMessage": "Human readable error message here - clients can display this to the user", "correlationId": "ID of the request - clients should display this for tracking purposes" } ```
PBharose commented 1 year ago

Logic for generating unique error codes could be as follows:

  1. Define a prefix for the error code, for example "P2M" as in the example provided.
  2. Generate a unique sequence number for each error, starting from 0001.
  3. Combine the prefix and the sequence number to create the error code, for example "P2M0001".
  4. Store the generated error code in a persistent storage, such as a database or a file, to ensure uniqueness across requests.
  5. Retrieve the error code when generating an error response and include it in the "errorCode" field.
PBharose commented 1 year ago

@Rajeshwari-Bhandari Please post the status here. If completed we can close this issue

Rajeshwari-Bhandari commented 1 year ago

Completed the task with no issues.