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 #211

Merged
merged 2 commits into from
Dec 19, 2024
Merged

Improve errors #211

merged 2 commits into from
Dec 19, 2024

Conversation

mifi
Copy link
Collaborator

@mifi mifi commented Dec 13, 2024

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.

See which implementation you like more, this or #212

closes #154

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.
mifi added a commit that referenced this pull request Dec 13, 2024
...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`
README.md Outdated Show resolved Hide resolved
@kvz kvz requested a review from remcohaszing December 16, 2024 07:14
@remcohaszing
Copy link
Member

I suggest we go with #212 instead.

@mifi
Copy link
Collaborator Author

mifi commented Dec 18, 2024

ok nice. please review this PR also, because #212 branches off of this PR. alternative you can review a diff between #212 and main. or we can merge #212 into this PR and you can review this PR.

src/ApiError.ts Outdated Show resolved Hide resolved
test/unit/mock-http.test.ts Outdated Show resolved Hide resolved
test/unit/mock-http.test.ts Outdated Show resolved Hide resolved
src/Transloadit.ts Outdated Show resolved Hide resolved
mifi added a commit that referenced this pull request Dec 19, 2024
@mifi
Copy link
Collaborator Author

mifi commented Dec 19, 2024

I agree with all your suggestions. I've added them to the other PR #212

@kvz
Copy link
Member

kvz commented Dec 19, 2024

Do i understand we first need to merge this and then that?

@mifi
Copy link
Collaborator Author

mifi commented Dec 19, 2024

doesn't really matter i think

@mifi
Copy link
Collaborator Author

mifi commented Dec 19, 2024

if we merge #212, this PR will contain that pr's commits too

* 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]>
@kvz
Copy link
Member

kvz commented Dec 19, 2024

Alright! Closing in favor of #212

@kvz kvz closed this Dec 19, 2024
@codecov-commenter
Copy link

codecov-commenter commented Dec 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.36%. Comparing base (0e0e9e1) to head (dc67a98).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #211      +/-   ##
==========================================
- Coverage   69.60%   68.36%   -1.25%     
==========================================
  Files           6        6              
  Lines         612      588      -24     
  Branches      121      113       -8     
==========================================
- Hits          426      402      -24     
  Misses        186      186              
Flag Coverage Δ
unittests 68.36% <100.00%> (-1.25%) ⬇️

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
Copy link
Collaborator Author

mifi commented Dec 19, 2024

oops what i meant is that yes both PRs need to be merged but the order doesn't matter

@mifi mifi reopened this Dec 19, 2024
@mifi
Copy link
Collaborator Author

mifi commented Dec 19, 2024

i assume your intention was to merge this PR also then, so i'll do that now :)

@mifi mifi merged commit 94356cb into main Dec 19, 2024
18 checks passed
@mifi mifi deleted the improve-errors2 branch December 19, 2024 11:04
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.

Improve error debuggability
4 participants