Skip to content

Commit 80628d4

Browse files
authored
Merge pull request RonRadtke#210 from eleretic/master
Add Custom Error for cancel task reject
2 parents 9eedb55 + 0527211 commit 80628d4

File tree

5 files changed

+18
-3
lines changed

5 files changed

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

fetch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from "./fs";
44
import getUUID from "./utils/uuid";
55
import {DeviceEventEmitter} from "react-native";
66
import {FetchBlobResponse} from "./class/ReactNativeBlobUtilBlobResponse";
7+
import CanceledFetchError from "./class/ReactNativeBlobUtilCanceledFetchError";
78
import ReactNativeBlobUtil from "./codegenSpecs/NativeBlobUtils";
89

910
const emitter = DeviceEventEmitter;
@@ -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

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const ReactNativeBlobUtil: ReactNativeBlobUtilStatic;
77
export type ReactNativeBlobUtil = ReactNativeBlobUtilStatic;
88
export default ReactNativeBlobUtil;
99
import {filedescriptor} from './types';
10+
import CanceledFetchError from './class/ReactNativeBlobUtilCanceledFetchError'
1011

1112
interface ReactNativeBlobUtilStatic {
1213
fetch(method: Methods, url: string, headers?: { [key: string]: string }, body?: any
@@ -29,6 +30,7 @@ interface ReactNativeBlobUtilStatic {
2930
polyfill: Polyfill;
3031
// this require external module https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/oboe
3132
JSONStream: any;
33+
CanceledFetchError: CanceledFetchError
3234
}
3335

3436
export interface Polyfill {

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import ios from './ios';
1515
import JSONStream from './json-stream';
1616
import {config, fetch} from './fetch';
1717
import URIUtil from "./utils/uri";
18+
import CanceledFetchError from "./class/ReactNativeBlobUtilCanceledFetchError";
1819

1920
const {
2021
ReactNativeBlobUtilSession,
@@ -70,5 +71,6 @@ export default {
7071
wrap,
7172
polyfill,
7273
JSONStream,
73-
MediaCollection
74+
MediaCollection,
75+
CanceledFetchError
7476
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-blob-util",
3-
"version": "0.17.1",
3+
"version": "0.17.2",
44
"description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
55
"main": "index",
66
"scripts": {

0 commit comments

Comments
 (0)