chai-backend
chai-backend copied to clipboard
Hardcoding the status code here overrides the one set in the try block. Instead, use error?.statusCode to preserve it.
Issue: The current implementation of error handling in the authentication middleware hardcodes the status code in the catch block, which overrides any status code set in the try block. This can result in inaccurate status codes being sent to the client.
Solution: Modified the error handling to use error?.statusCode instead of a hardcoded status code. This change ensures that the status code specified in the try block is preserved and accurately reflected in the response.
Changes Made:
Replaced hardcoded status code in the catch block with error?.statusCode. Updated fallback to 401 and default message to "Token verification failed" if no status code or message is provided. Benefits:
Ensures accurate status codes are sent based on the context of the error. Enhances the flexibility and maintainability of error handling. Please review the changes and provide feedback. Thank you!