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

Improve errors alternative implementation #212

Merged
merged 7 commits into from
Dec 19, 2024
Merged

Conversation

mifi
Copy link
Collaborator

@mifi mifi commented Dec 13, 2024

Alternative implementation of #211 where ApiError has all the API response properties directly on it
instaed of inside a response property

  • ApiError.response.error -> ApiError.code
  • ApiError.response.message -> ApiError.rawMessage
  • ApiError.response.assembly_id -> ApiError.assemblyId
  • ApiError.response.assembly_ssl_url -> ApiError.assemblySslUrl

I kind of like this better (less typing)

closes #154

mifi added 2 commits December 14, 2024 00:14
...of #211 where `ApiError` has all the API response properties directly on it
instaed of inside a `response` object
- `ApiError.response.error` -> `ApiError.code`
- `ApiError.response.message` -> `ApiError.rawMessage`
- `ApiError.response.assembly_id` -> `ApiError.assemblyId`
- `ApiError.response.assembly_ssl_url` -> `ApiError.assemblySslUrl`
@mifi mifi changed the title Improve errors3 Improve errors alternative implementation Dec 13, 2024
@codecov-commenter
Copy link

codecov-commenter commented Dec 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (improve-errors2@c6e68f9). Learn more about missing BASE report.

Additional details and impacted files
@@                Coverage Diff                 @@
##             improve-errors2     #212   +/-   ##
==================================================
  Coverage                   ?   68.36%           
==================================================
  Files                      ?        6           
  Lines                      ?      588           
  Branches                   ?      113           
==================================================
  Hits                       ?      402           
  Misses                     ?      186           
  Partials                   ?        0           
Flag Coverage Δ
unittests 68.36% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mifi mifi mentioned this pull request Dec 13, 2024
@kvz kvz requested a review from remcohaszing December 16, 2024 07:16
Copy link
Member

@remcohaszing remcohaszing left a comment

Choose a reason for hiding this comment

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

Yes, I really like this! I like it better than #211

README.md Outdated Show resolved Hide resolved
@mifi mifi requested a review from remcohaszing December 19, 2024 04:15
@kvz kvz merged commit dc67a98 into improve-errors2 Dec 19, 2024
9 checks passed
@kvz kvz deleted the improve-errors3 branch December 19, 2024 08:17
mifi added a commit that referenced this pull request Dec 19, 2024
* Improve errors

Renamed `TransloaditError` to `ApiError`. Differences between `TransloaditError` and `ApiError`:
- Moved `TransloaditError.response.body` to `ApiError.response`
- Removed `TransloaditError.assemblyId` (can now be found in `ApiError.response.assembly_id`
- Removed `TransloaditError.transloaditErrorCode` (can now be found in `ApiError.response.error`
- `ApiError` does not inherit from `got.HTTPError`, but `ApiError.cause` will be the `got.HTTPError` instance that caused this error (except for when Tranloadit API responds with HTTP 200 and `error` prop set in JSON response, in which case cause will be `undefined`).

Note that (just like before) when the Transloadit API responds with an error we will always throw a `ApiError` - In all other cases (like request timeout, connection error, TypeError etc.), we don't wrap the error in `ApiError`.

Also improved error stack traces, added a unit test in `mock-http.test.ts` that verifies the stack trace.

* Improve errors alternative implementation (#212)

* make alternative implementation

...of #211 where `ApiError` has all the API response properties directly on it
instaed of inside a `response` object
- `ApiError.response.error` -> `ApiError.code`
- `ApiError.response.message` -> `ApiError.rawMessage`
- `ApiError.response.assembly_id` -> `ApiError.assemblyId`
- `ApiError.response.assembly_ssl_url` -> `ApiError.assemblySslUrl`

* fix formatting

* Update README.md

Co-authored-by: Remco Haszing <[email protected]>

* remove stack hack

#211 (comment)

* improve assertion

* fix typo

* fix formatting

---------

Co-authored-by: Remco Haszing <[email protected]>

---------

Co-authored-by: Remco Haszing <[email protected]>
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.

4 participants