Skip to content

fix: improve Msg91 error handling to extract API error messages - #133

Open
deepshekhardas wants to merge 2 commits into
utopia-php:mainfrom
deepshekhardas:fix/msg91-error-handling
Open

fix: improve Msg91 error handling to extract API error messages#133
deepshekhardas wants to merge 2 commits into
utopia-php:mainfrom
deepshekhardas:fix/msg91-error-handling

Conversation

@deepshekhardas

Copy link
Copy Markdown

No description provided.

@greptile-apps

greptile-appsBot commented Jun 17, 2026

Copy link
Copy Markdown

Greptile Summary

This PR improves the Msg91 SMS adapter's error handling in the non-200 response branch by extracting an actual error message from the API response body (checking message and error keys) rather than always returning the static string "Unknown error". When the extracted value is not a string, it is safely encoded with json_encode before being passed to addResult().

  • Introduces a fallback chain (messageerror"Unknown error") to surface meaningful API error messages.
  • Guards non-string field values with is_string() + json_encode(), preventing a potential TypeError from passing an array directly to addResult().

Confidence Score: 4/5

  • The change is safe and moves in the right direction, but the error-extraction logic still misses a type guard for non-array response values raised in prior review rounds, leaving one defect path unremedied.
  • The is_string + json_encode guard correctly prevents a TypeError when message or error is an array. However, $result['response'] can be a raw string when Msg91 returns a plain-text or HTML error body; in that case isset($result['response']['message']) resolves via PHP character-index access rather than array-key lookup, so the branch can still produce a misleading single-character error message — a defect path that was flagged in earlier review rounds and remains unaddressed.
  • src/Utopia/Messaging/Adapter/SMS/Msg91.php — the error extraction block around the isset($result['response']['message']) check warrants a second look.

Important Files Changed

FilenameOverview
src/Utopia/Messaging/Adapter/SMS/Msg91.phpAdds structured error extraction from the Msg91 API response, handling both message and error keys with a string/json_encode guard; the string-vs-array response type guard flagged in prior review threads is still absent.

Reviews (7): Last reviewed commit: "fix: guard Msg91 error extraction agains..." | Re-trigger Greptile

Comment threadsrc/Utopia/Messaging/Adapter/SMS/Msg91.php
Comment threadsrc/Utopia/Messaging/Adapter/SMS/Msg91.php
@deepshekhardas

Copy link
Copy Markdown
Author

Following up - Msg91 error handling fix. Let me know if changes needed.

Sign up for freeto 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

@deepshekhardas