Skip to content

Commit

Permalink
Update rate limit error
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Oct 26, 2023
1 parent 23be982 commit 87005a5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/server/datahub/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ export function datahubMutationWrapper<
const rateLimitError = errors.find(
(e: any) => e?.code === 'TOO_MANY_REQUESTS_PER_TIME_RANGE'
) as any
const rateLimitData = rateLimitError?.data
if (rateLimitError)
const rateLimitData = rateLimitError?.payload
if (rateLimitError) {
const range = Math.max(rateLimitData.msRange / 1000, 1)
const timeLeft = Math.max(rateLimitData.msBeforeNext / 1000, 1)
throw new Error(
`You can only send ${rateLimitData.maxPoints} messages per ${
rateLimitData.range / 1000
} seconds`,
`You can only send ${
rateLimitData.maxPoints
} messages per ${range} seconds${
timeLeft > 1 ? `(${timeLeft} seconds remaining)` : ''
}`,
{
cause: RATE_LIMIT_EXCEEDED,
}
)
}
}
throw err
}
Expand Down

0 comments on commit 87005a5

Please sign in to comment.