[READY] use http-status for api responses#621
Merged
Sharqiewicz merged 5 commits intoMay 12, 2025
Merged
Conversation
✅ Deploy Preview for pendulum-pay canceled.
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR replaces hard-coded HTTP status codes with the httpStatus constants to standardize API responses.
- Updates in various controllers and middlewares to use descriptive httpStatus constants.
- Improves consistency of error and success responses across the API.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| api/webhooks-cache/index.js | Replaces numerical status codes with httpStatus constants for Unauthorized, Forbidden, and OK responses. |
| api/src/api/middlewares/validators.ts | Updates error responses in various validators to use httpStatus.BAD_REQUEST. |
| api/src/api/middlewares/auth.ts | Uses httpStatus constants for Unauthorized and Internal Server Error responses. |
| api/src/api/controllers/subsidize.controller.ts | Uses httpStatus.INTERNAL_SERVER_ERROR for error responses. |
| api/src/api/controllers/stellar.controller.ts | Replaces numeric status codes with httpStatus.INTERNAL_SERVER_ERROR and OK. |
| api/src/api/controllers/siwe.controller.ts | Updates nonces and signature validation to use httpStatus constants across responses. |
| api/src/api/controllers/price.controller.ts | Standardizes error responses to use httpStatus constants including BAD_REQUEST, BAD_GATEWAY, INTERNAL_SERVER_ERROR, and OK. |
| api/src/api/controllers/pendulum.controller.ts | Updates funding account and error responses with httpStatus constants. |
| api/src/api/controllers/moonbeam.controller.ts | Uses httpStatus constants for error responses. |
| api/src/api/controllers/googleSpreadSheet.controller.ts | Uses httpStatus constants for OK and Internal Server Error responses. |
| api/src/api/controllers/brla.controller.ts | Applies httpStatus constants across various error and success response scenarios. |
Comment on lines
+44
to
+65
| } catch (error) { | ||
| console.error('Error parsing SIWE message: ', error); | ||
| res.status(httpStatus.BAD_REQUEST).json({ | ||
| error: 'Invalid SIWE message', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const message = error instanceof Error ? error.message : 'Unknown error'; | ||
| res.status(500).json({ error: `Could not validate signature: ${message}` }); | ||
| try { | ||
| if (!(await siweNonceService.validate(siweMessage.address, siweMessage.nonce, signature))) { | ||
| throw new Error('Signature verification failed'); | ||
| } | ||
| (req.session as SessionData).siwe = { address: siweMessage.address }; | ||
| await req.session.save(); | ||
| res.json({ success: true }); | ||
| } catch (error) { | ||
| console.error('Error validating signature: ', error); | ||
| res.status(httpStatus.UNAUTHORIZED).json({ error: 'Invalid signature' }); | ||
| } | ||
| } catch (error) { | ||
| console.error('Error processing SIWE validation: ', error); | ||
| res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ error: 'Internal Server Error' }); |
There was a problem hiding this comment.
[nitpick] Consider refactoring the nested try-catch blocks in the validateSiweSignature function to simplify error handling and improve clarity.
ebma
approved these changes
May 6, 2025
Member
Author
|
@ebma the env var isn't defined in the .env.example to not trigger the validation |
Member
|
Let's merge this tomorrow in order not to risk anything with our production release for today. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
a new env variable
SLACK_USER_ID( Closes: #470 )use
http-statusfor api statuses ( Closes: #612 )