-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(middleware): mimic
GET
behavior on /api/v1/sessions
and log …
…requests
- Loading branch information
1 parent
4d8ae49
commit d86deb9
Showing
3 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
60 changes: 58 additions & 2 deletions
60
pages/api/v1/_responses/rate-limit-reached-sessions.public.js
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import snakeize from 'snakeize'; | ||
import logger from 'infra/logger.js'; | ||
import { TooManyRequestsError } from 'errors/index.js'; | ||
|
||
export default function handler(request, response) { | ||
const error = new TooManyRequestsError({}); | ||
response.status(error.statusCode).json(error); | ||
const error = new TooManyRequestsError({ | ||
context: { | ||
method: request.method, | ||
url: request.url, | ||
body: request.body, | ||
}, | ||
}); | ||
|
||
logger.error(snakeize(error)); | ||
delete error.context; | ||
|
||
response.status(error.statusCode).json(snakeize(error)); | ||
} |