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:
2023-08-12 01:32:02 +03:00
parent 3bf00cea6a
commit b12f19ac51
5 changed files with 60 additions and 29 deletions

View File

@ -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 }