Skip to content

Commit f90ac3e

Browse files
committed
Add exported custom error for cancel tasks
1 parent 2e14e6b commit f90ac3e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CanceledFetchError extends Error {
2+
constructor(message) {
3+
super(message);
4+
this.name = CanceledFetchErrorName;
5+
}
6+
}
7+
8+
export const CanceledFetchErrorName = 'ReactNativeBlobUtilCanceledFetch'
9+
10+
export default CanceledFetchError

fetch.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import {ReactNativeBlobUtilConfig} from "./types";
1+
import { ReactNativeBlobUtilConfig } from "./types";
22
import URIUtil from "./utils/uri";
33
import fs from "./fs";
44
import getUUID from "./utils/uuid";
5-
import {DeviceEventEmitter} from "react-native";
6-
import {FetchBlobResponse} from "./class/ReactNativeBlobUtilBlobResponse";
5+
import { DeviceEventEmitter } from "react-native";
6+
import { FetchBlobResponse } from "./class/ReactNativeBlobUtilBlobResponse";
7+
import { CanceledFetchError } from ".class/ReactNativeBlobUtilCanceledFetchError";
78
import ReactNativeBlobUtil from "./codegenSpecs/NativeBlobUtils";
89

910
const emitter = DeviceEventEmitter;
@@ -55,7 +56,7 @@ emitter.addListener("ReactNativeBlobUtilMessage", (e) => {
5556
* @return {function} This method returns a `fetch` method instance.
5657
*/
5758
export function config(options: ReactNativeBlobUtilConfig) {
58-
return {fetch: fetch.bind(options)};
59+
return { fetch: fetch.bind(options) };
5960
}
6061

6162
/**
@@ -105,7 +106,7 @@ function fetchFile(options = {}, method, url, headers = {}, body): Promise {
105106
stream.open();
106107
info = {
107108
state: "2",
108-
headers: {'source': 'system-fs'},
109+
headers: { 'source': 'system-fs' },
109110
status: 200,
110111
respType: 'text',
111112
rnfbEncode: headers.encoding || 'utf8'
@@ -328,7 +329,7 @@ export function fetch(...args: any): Promise {
328329
subscriptionUpload.remove();
329330
stateEvent.remove();
330331
ReactNativeBlobUtil.cancelRequest(taskId, fn);
331-
promiseReject(new Error("canceled"));
332+
promiseReject(new CanceledFetchError("canceled"));
332333
};
333334
promise.taskId = taskId;
334335

0 commit comments

Comments
 (0)