[Http] Add helper function to check if the error is `FetchError`
Closed this issue · 2 comments
kiaking commented
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) => {
// ...
})
}