Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classify sms errors #5012

Merged
merged 30 commits into from
Feb 19, 2025
Merged

Classify sms errors #5012

merged 30 commits into from
Feb 19, 2025

Conversation

tung2744
Copy link
Contributor

@tung2744 tung2744 commented Feb 12, 2025

ref DEV-2454
Test with authgear/authgear-sms-gateway#23

// This is not something we understand, check the status code to determine if it is a success
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
return nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check if the error is produced by the json package. Please add tests to ensure this does not break legacy gateways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally we don't even try to read the response and only check the statusCode. If we want to ensure it behave the same as before we should still treat it as success even it is not a json parsing error.

@tung2744
Copy link
Contributor Author

I've addressed the comments above, but e2e tests are failing so I'm checking.

@tung2744 tung2744 changed the title [WIP] Classify sms errors Classify sms errors Feb 14, 2025
@tung2744
Copy link
Contributor Author

This is ready for review, thanks!

@tung2744 tung2744 changed the title Classify sms errors [WIP] Classify sms errors Feb 17, 2025
@tung2744
Copy link
Contributor Author

tung2744 commented Feb 17, 2025

TODO:

  • Update translations

@tung2744 tung2744 changed the title [WIP] Classify sms errors Classify sms errors Feb 17, 2025
if err != nil {
return err
}

return nil
responseBody, err := ParseResponseBody(jsonText)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the existing SMS deno hook return {"code": 1}, the json parsing will fail, but we should still treat this as success. Please add a test case to show this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, sms deno hook is not allowed to return anything. So existing deno hooks should return null.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by not allowed? I think the hook can return anything they want, given that they write enough type annotation to bypass type checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right that the hook can return anything if the function return type is set to any. However I think existing hooks are configured by us so there should be no hook written using incorrect return type? In fact I am not sure if there is anyone using the deno sms hook after we have our sms gateway deployed?

WebHook: webhook,
Client: &mockWebHookClient{
ResponseStatusCode: 200,
ResponseBody: io.NopCloser(strings.NewReader("")),
Copy link
Collaborator

@louischan-oursky louischan-oursky Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test case in which the response body is {"code": 1}.

@tung2744
Copy link
Contributor Author

Rebased and added b0e11ab for deno hook backward compatibility.

@louischan-oursky louischan-oursky merged commit 4f59849 into authgear:main Feb 19, 2025
10 checks passed
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.

2 participants