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-apps Bot commented Jun 17, 2026

Copy link
Copy Markdown

Greptile Summary

This PR improves error reporting in the Msg91 SMS adapter by extracting the actual API error message from the response body (checking message and error keys) instead of always falling back to the static string "Unknown error". Non-string values (e.g., arrays) are serialised with json_encode() so callers always receive a string.

  • The new logic correctly handles both string and non-string values in the error fields, addressing the pre-existing gap where structured API errors were silently swallowed.
  • request() can return response as a plain string when the body is not valid JSON; the current implementation does not guard for this case, so the isset() calls on a non-array may produce a deprecation notice and a garbled single-character error message in practice.

Confidence Score: 5/5

The change is safe to merge; it strictly improves the error message surfaced to callers and does not touch the success path or any shared logic.

The change is narrow and low-risk — it replaces a hard-coded "Unknown error" string with an extracted API message inside a single else-branch. The one edge case (non-JSON response body) is unlikely for a JSON API and would only degrade error readability, not corrupt data or break delivery tracking.

No files require special attention beyond the inline suggestion on Msg91.php.

Important Files Changed

Filename Overview
src/Utopia/Messaging/Adapter/SMS/Msg91.php Improves error handling in the non-200 branch by extracting message or error from the parsed API response instead of always returning "Unknown error"; missing is_array() guard could produce garbled single-character error strings when the response body is plain text.

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

Comment thread src/Utopia/Messaging/Adapter/SMS/Msg91.php
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