Skip to content

Commit

Permalink
log an error to sentry if an upstream service responds with `429 Too …
Browse files Browse the repository at this point in the history
…Many Requests` (badges#9505)

* log an error to sentry if an upstream service responds with 429 Too Many Requests

* fix tests
  • Loading branch information
chris48s committed Aug 27, 2023
1 parent 94a148b commit 5353782
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/base-service/check-error-response.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import log from '../server/log.js'
import { NotFound, InvalidResponse, Inaccessible } from './errors.js'

const defaultErrorMessages = {
Expand Down Expand Up @@ -25,6 +26,13 @@ export default function checkErrorResponse(httpErrors = {}) {
error = new InvalidResponse(props)
}
}

if (res.statusCode === 429) {
log.error(
new Error(`429 Too Many Requests calling ${res.requestUrl.origin}`),
)
}

if (error) {
error.response = res
error.buffer = buffer
Expand Down
2 changes: 1 addition & 1 deletion core/base-service/check-error-response.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('async error handler', function () {

context('when status is 429', function () {
const buffer = Buffer.from('some stuff')
const res = { statusCode: 429 }
const res = { statusCode: 429, requestUrl: new URL('https://example.com/') }

it('throws InvalidResponse', async function () {
try {
Expand Down

0 comments on commit 5353782

Please sign in to comment.