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

Propagate Django error messages from Transaction Service #1226

Merged
merged 2 commits into from
Mar 1, 2024

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented Feb 29, 2024

Summary

This adds an error mapper to the TransactionApi service that maps Django error messages (nonFieldErrors[0]) if present to be the "standard" error message.

Changes

  • Add TransactionApi['mapError'] and use it within all calls
  • Add test coverage for TransactionApi

@iamacook iamacook self-assigned this Feb 29, 2024
Comment on lines -29 to -32
const httpErrorFactory = {
from: jest.fn(),
} as jest.MockedObjectDeep<HttpErrorFactory>;
const mockHttpErrorFactory = jest.mocked(httpErrorFactory);
Copy link
Member Author

Choose a reason for hiding this comment

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

I migrated to using the real HttpErrorFactory as we were mocking and testing the mocked functionality which didn't make much sense. Would welcome your thoughts regarding this.

@coveralls
Copy link

coveralls commented Feb 29, 2024

Pull Request Test Coverage Report for Build 8100115384

Details

  • 41 of 41 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 93.853%

Totals Coverage Status
Change from base Build 8081216656: 0.2%
Covered Lines: 6183
Relevant Lines: 6369

💛 - Coveralls

@iamacook iamacook marked this pull request as ready for review February 29, 2024 08:36
@iamacook iamacook requested a review from a team as a code owner February 29, 2024 08:36
Copy link
Member

@hectorgomezv hectorgomezv left a comment

Choose a reason for hiding this comment

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

I've only left small nits, but it LGTM 👏🏻

Glad to see a lot of tests were added 💪🏻

Comment on lines 868 to 873
// Map Django error as "standard" error message if present
const djangoError = get(error.data, 'nonFieldErrors[0]');
if (djangoError) {
return new NetworkResponseError(error.url, error.response, {
message: djangoError,
});
Copy link
Member

Choose a reason for hiding this comment

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

Nit: should we abstract from the technology used by the data source? I mean, what about changing the django references here and in the tests for another generic concept like transactionService?

Copy link
Member

Choose a reason for hiding this comment

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

And also other nits:

  • nonFieldErrors[0] might be extracted to a class constant, wdyt?
  • This assumes we are only interested in the first error in the payload, aren't we? I'm ok with this as long as this is ok for the clients.

Copy link
Member Author

Choose a reason for hiding this comment

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

I generalised all references to "Django" (preferring "Transaction Service") in 931505d, as well as moving the path to a constant. I also added a comment explaining the reasoning for returning the first error element - a string is preferred.

@hectorgomezv hectorgomezv self-requested a review March 1, 2024 09:35
@iamacook iamacook merged commit cbe78f1 into main Mar 1, 2024
16 checks passed
@iamacook iamacook deleted the map-transaction-api-error branch March 1, 2024 09:45
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.

3 participants