Skip to content

Commit

Permalink
fix: return proper error if sms rate limit is exceeded (supabase#1647)
Browse files Browse the repository at this point in the history
## What kind of change does this PR introduce?
* Fixes supabase#1629 
* Previously, rate limit errors were being returned as an internal
server error, which is incorrect. This PR checks for the underlying
error type returned and ensures that rate limit errors are surfaced
appropriately.

## What is the current behavior?

Please link any relevant issues here.

## What is the new behavior?

Feel free to include screenshots if it includes visual changes.

## Additional context

Add any other context or screenshots.
  • Loading branch information
kangmingtay authored Jul 4, 2024
1 parent 85361b7 commit 3c8d765
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ func (a *API) UserUpdate(w http.ResponseWriter, r *http.Request) error {
return internalServerError("Error finding SMS provider").WithInternalError(terr)
}
if _, terr := a.sendPhoneConfirmation(r, tx, user, params.Phone, phoneChangeVerification, smsProvider, params.Channel); terr != nil {
if errors.Is(terr, MaxFrequencyLimitError) {
return tooManyRequestsError(ErrorCodeOverSMSSendRateLimit, generateFrequencyLimitErrorMessage(user.PhoneChangeSentAt, config.Sms.MaxFrequency))
}
return internalServerError("Error sending phone change otp").WithInternalError(terr)
}
}
Expand Down

0 comments on commit 3c8d765

Please sign in to comment.