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

fix gocardless error handling #439

Merged
merged 4 commits into from
Aug 25, 2024
Merged

Conversation

matt-fidd
Copy link
Contributor

@matt-fidd matt-fidd commented Aug 20, 2024

Helps with #431

It looks like GoCardless error handling wasn't working at all as handleGoCardlessError was never reached when client.${method} threw an error.

Cheking the GCL docs, there is no behaviour defined that would return a 200 response with an error status code so Axios should always throw an error.

This changes fixes that, and allows the basic rate limit error to be sent back to the client.

@actual-github-bot actual-github-bot bot changed the title fix gocardless error handling [WIP] fix gocardless error handling Aug 20, 2024
@matt-fidd matt-fidd changed the title [WIP] fix gocardless error handling fix gocardless error handling Aug 20, 2024
handleGoCardlessError(response);
let response;
try {
response = client.deleteRequisition(requisitionId);
Copy link
Contributor

@MikesGlitch MikesGlitch Aug 25, 2024

Choose a reason for hiding this comment

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

Nit: You can return this response directly rather than declaring "response" outside of the try.

I think the last return response; is unreachable due to handleGoCardlessError always throwing

Same with the others

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think l prefer leaving it as-is makes any expandability in the future a little easier, and IMO makes the function slightly easier to read. They're tiny little functions but my go to quick check for return value when reading tends to be the bottom.

  1. Stuff happens
  2. Handle errors
  3. Default return case for success

As opposed to

  1. Stuff happens and returns if success
  2. Error

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair. LGTM :shipit:

Copy link
Contributor

@MikesGlitch MikesGlitch left a comment

Choose a reason for hiding this comment

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

Small nit, but LGTM

@matt-fidd matt-fidd merged commit 2b37d5a into actualbudget:master Aug 25, 2024
7 checks passed
@matt-fidd matt-fidd deleted the gcl-error branch August 25, 2024 16:53
MMichotte pushed a commit to MMichotte/actual-server that referenced this pull request Sep 9, 2024
* fix gocardless error handling

* release note

* remove redundant tests

* tcrasset feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants