Skip to content

fix(api): answer an SMS guard refusal with its status - #396

Merged
roncodes merged 1 commit into
release/v0.6.72from
fix/sms-guard-refusal-status
Oct 13, 2026
Merged

roncodes merged 1 commit into
release/v0.6.72from
fix/sms-guard-refusal-status

Conversation

@roncodes

Copy link
Copy Markdown
Member

Summary

Follow-up to #393 / #395. The customer and driver login-with-sms, request-creation-code and forgot-password endpoints wrap their SMS send in a catch-all, so a refusal from the SMS guard (SmsBlockedException, a RuntimeException) was flattened into the generic 400 send error or into the email fallback. An app could neither explain the refusal to the person nor back off.

The refusal now reaches the caller with the status it carries, as the storefront endpoints already do:

Status When
422 the number can never be texted
429 + Retry-After a cooldown on that number, or the organization's budget
423 texting is paused for the organization or the platform

Login keeps its email fallback: with an email on file the code goes by email and the response says method: email; the refusal is the answer only when nothing else can carry the code.

Changes

  • Api/v1/CustomerController: requestCreationCode and forgotPassword catch SmsBlockedException before the generic catch; loginWithPhone remembers why the text failed and answers with it when the email fallback is unavailable or also fails. Two small helpers, smsBlockedResponse() and sendFailureResponse(), live in the controller (a shared trait in another namespace would break the test harnesses' namespaced response() fakes).
  • Api/v1/DriverController: same for loginWithPhone and forgotPassword.
  • Tests in the three existing harnesses: ApiCustomerControllerContractsTest (423 on creation code with Retry-After, 429 on login without email, email fallback on login with email, 422 on forgot-password), ApiDriverPasswordContractsTest (429 on forgot-password), DriverControllerAuthFlowsTest (email fallback, then 423 with Retry-After once the email is gone, driven by a Twilio fake that throws the refusal).

Validation

php -l and php-cs-fixer --dry-run on the five files are clean. The suite was not run locally (the Pest runner does not work on this machine); CI stays blocked on the fleetbase/core-api ^1.6.69 tag as on #395.

Docs: fleetbase/fleetbase.io#128 and fleetbase/postman#66 describe this behaviour.

The customer and driver login, creation-code and forgot-password endpoints
wrap their SMS send in a catch-all, so a refusal from the guard (a
RuntimeException) was flattened into the generic 400 send error, or into
the email fallback, and an app could neither explain it nor back off.

The refusal now reaches the caller with the status it carries: 422 for a
number that can never be texted, 429 with Retry-After for a cooldown or
budget, 423 while texting is paused. Login still falls back to email when
the account has an address; the refusal is the answer only when nothing
else can carry the code.
@roncodes
roncodes merged commit 2440bdc into release/v0.6.72 Oct 13, 2026
4 of 6 checks passed
@roncodes
roncodes deleted the fix/sms-guard-refusal-status branch October 13, 2026 11:04
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.

1 participant