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

add in full cause to thrown errors #94

Merged
merged 2 commits into from
Aug 12, 2024

Conversation

courcelan
Copy link
Contributor

this PR (for issue #93) updates the reporting for a thrown Error.

Errors now report with the following:

  • err.message: the detail of the error and status code
  • err.cause: info on what was passed to the API

err.cause contains:

  • data: the detail of the error
  • headers: any headers
  • status: response status code
  • statusText: any response status text
  • config: the configuration used in the fetch
  • params: any parameters passed to the reques
  • type: the content type requested
  • url: object contain the URL schema

Please note that any reference to auth_token is removed from the resulting cause.

@ViolanteCodes
Copy link
Contributor

@courcelan can you update the commit message to use fix: so the CI/CD deploys?

removes auth_token from reporting

update tests
@courcelan courcelan force-pushed the 93-provide-error-status-code branch from 341b027 to 6ede5e4 Compare August 6, 2024 14:21
@courcelan
Copy link
Contributor Author

@courcelan can you update the commit message to use fix: so the CI/CD deploys?

done

Copy link
Contributor

@marcinpece-apptension marcinpece-apptension left a comment

Choose a reason for hiding this comment

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

tests/basic.html Outdated Show resolved Hide resolved
examples/hooks.html Outdated Show resolved Hide resolved
examples/hooks.html Outdated Show resolved Hide resolved
tests/hooks.html Outdated Show resolved Hide resolved
tests/hooks.html Outdated Show resolved Hide resolved
lib/useButter.js Outdated
@@ -123,18 +123,38 @@ export default function useButter(type, butterConfig) {
detail: errorDetail
Copy link
Contributor

Choose a reason for hiding this comment

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

In some cases error detail might be not in detail prop. Should we cover somehow or current state is ok?
https://share.zight.com/8LuNRWmL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for this @marcinpece-apptension, I've updated the code to handle a more general set of error keys/values. Please give this all another check.

Comment on lines +122 to +143
const errors = await errorPayload.response.json();

const mappedParams = Object.fromEntries(
Object.entries(errorPayload.params)
.filter(([key]) => key !== 'auth_token')
);

const url = new URL(errorPayload.response.url);

// Remove auth_token from URL search params
url.searchParams.delete('auth_token');

const cause = {
data: errors,
headers: errorPayload.response.headers,
status: errorPayload.response.status,
statusText: errorPayload.response.statusText,
config: errorPayload.config,
params: mappedParams,
type,
url
};
Copy link
Contributor

Choose a reason for hiding this comment

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

💚

@@ -129,7 +129,7 @@ test(
catch (error) {
await expect(error).toBeDefined();
await expect(error).toBeInstanceOf(Error);
await expect(error.message).toEqual("Error: Not found");
await expect(error.message).toEqual("Error: Not found (404)");
Copy link
Contributor

Choose a reason for hiding this comment

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

I have one error while running tests https://share.zight.com/L1uEo6mm

@ViolanteCodes ViolanteCodes merged commit d91d47f into master Aug 12, 2024
@marcinpece-apptension
Copy link
Contributor

@ViolanteCodes Has the error in the test been fixed before merge?

@courcelan
Copy link
Contributor Author

@marcinpece-apptension yes. I caught it in #95 and updated there prior to you mentioning it. so we should be all good.

@marcinpece-apptension
Copy link
Contributor

Cool 🎉 Thanks

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

Successfully merging this pull request may close these issues.

3 participants