Skip to content

[READY] use http-status for api responses#621

Merged
Sharqiewicz merged 5 commits into
stagingfrom
612-use-http-status-library-for-api-status-handling-in-the-api
May 12, 2025
Merged

[READY] use http-status for api responses#621
Sharqiewicz merged 5 commits into
stagingfrom
612-use-http-status-library-for-api-status-handling-in-the-api

Conversation

@Sharqiewicz
Copy link
Copy Markdown
Member

@Sharqiewicz Sharqiewicz commented May 5, 2025

a new env variable SLACK_USER_ID ( Closes: #470 )
use http-status for api statuses ( Closes: #612 )

@Sharqiewicz Sharqiewicz linked an issue May 5, 2025 that may be closed by this pull request
@Sharqiewicz Sharqiewicz requested review from a team and Copilot May 5, 2025 18:55
@netlify
Copy link
Copy Markdown

netlify Bot commented May 5, 2025

Deploy Preview for pendulum-pay canceled.

Name Link
🔨 Latest commit 98a0f29
🔍 Latest deploy log https://app.netlify.com/sites/pendulum-pay/deploys/681a007aba777c0008397508

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' });
Copy link

Copilot AI May 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider refactoring the nested try-catch blocks in the validateSiweSignature function to simplify error handling and improve clarity.

Copilot uses AI. Check for mistakes.
@Sharqiewicz Sharqiewicz changed the title use http-status for api responses [READY] use http-status for api responses May 6, 2025
@Sharqiewicz
Copy link
Copy Markdown
Member Author

@ebma the env var isn't defined in the .env.example to not trigger the validation

@ebma
Copy link
Copy Markdown
Member

ebma commented May 6, 2025

Let's merge this tomorrow in order not to risk anything with our production release for today.

@Sharqiewicz Sharqiewicz merged commit 86513d8 into staging May 12, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use http-status library for api status handling in the /api Tag relevant person for the funding account messages

3 participants