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

[Http] Add helper function to check if the error is FetchError #541

Open
kiaking opened this issue Jun 20, 2024 · 2 comments · May be fixed by #539
Open

[Http] Add helper function to check if the error is FetchError #541

kiaking opened this issue Jun 20, 2024 · 2 comments · May be fixed by #539
Assignees
Labels
enhancement New feature or request

Comments

@kiaking
Copy link
Member

kiaking commented Jun 20, 2024

When dealing with errors, it would be nice to have a function to assert the error is FetchError so that we can access underlining properties.

import { isFetchError } from 'sefirot/Http/Http'

const m = useMutation(() => ...)

try {
  m.execute()
} catch (e) {
  if (isFetchError(e)) {
    if (e.data === 'Email already exists') {
      // ...
    }
  }
}

And, maybe we could have more powerful API too? Not sure.

try {
  m.execute()
} catch (e) {
  // Throw `e` if the error is not FetchError.
  // Else call closure.
  handleFetchErrorOrThrow(e, (e) => {
    // ...
  })
}
@kiaking kiaking added the enhancement New feature or request label Jun 20, 2024
@brc-dd
Copy link
Member

brc-dd commented Jun 20, 2024

Already added isFetchError in #539 🫠 should we export it form Api or Http?

@kiaking
Copy link
Member Author

kiaking commented Jun 20, 2024

Already added isFetchError in #539 🫠

That's my man 😄

should we export it form Api or Http?

Good point. Wasn't thinking about that. Hmmm I think it should be from Http...? Because the error is coming from Http and not from API 🤔 ...

@kiaking kiaking linked a pull request Jun 20, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants