forked from polka_billy/porridger
Fixed useSend loading flow on abort
Made data null on error Made it remain in loading state on refetch and remount abortion
This commit is contained in:
@ -1,7 +1,21 @@
|
||||
const isAborted = (err: Error) => (
|
||||
const isAborted = <T>(err: Error): err is AbortError<T> => (
|
||||
err.name === 'AbortError'
|
||||
)
|
||||
|
||||
type AbortErrorMessage = 'resent' | 'unmount' | 'cancel'
|
||||
|
||||
class AbortError<T> extends DOMException {
|
||||
readonly fallback: T | undefined
|
||||
message: AbortErrorMessage
|
||||
|
||||
constructor(message: AbortErrorMessage, fallback?: T) {
|
||||
super(message, 'AbortError')
|
||||
this.message = message
|
||||
|
||||
this.fallback = fallback
|
||||
}
|
||||
}
|
||||
|
||||
function handleHTTPErrors(res: Response) {
|
||||
if (!res.ok) {
|
||||
switch (res.status) {
|
||||
@ -16,4 +30,4 @@ function handleHTTPErrors(res: Response) {
|
||||
}
|
||||
}
|
||||
|
||||
export { isAborted, handleHTTPErrors }
|
||||
export { isAborted, AbortError, handleHTTPErrors }
|
||||
|
Reference in New Issue
Block a user