@inweb/client 25.3.17 → 25.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.js +698 -527
- package/dist/client.js.map +1 -1
- package/dist/client.min.js +1 -1
- package/dist/client.module.js +473 -484
- package/dist/client.module.js.map +1 -1
- package/lib/Api/Assembly.d.ts +32 -8
- package/lib/Api/ClashTest.d.ts +1 -1
- package/lib/Api/Client.d.ts +2 -3
- package/lib/Api/Fetch.d.ts +6 -0
- package/lib/Api/{impl/FetchError.d.ts → FetchError.d.ts} +2 -0
- package/lib/Api/File.d.ts +34 -10
- package/lib/Api/HttpClient.d.ts +9 -3
- package/lib/Api/IHttpClient.d.ts +10 -4
- package/lib/Api/Job.d.ts +1 -1
- package/lib/Api/Model.d.ts +33 -9
- package/lib/Api/Project.d.ts +3 -3
- package/lib/Api/User.d.ts +1 -1
- package/lib/Api/Utils.d.ts +11 -0
- package/lib/Api/XMLHttp.d.ts +7 -0
- package/lib/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/Api/Assembly.ts +76 -70
- package/src/Api/ClashTest.ts +10 -19
- package/src/Api/Client.ts +92 -56
- package/src/Api/Fetch.ts +84 -0
- package/src/Api/{impl/http.ts → FetchError.ts} +33 -1
- package/src/Api/File.ts +112 -117
- package/src/Api/HttpClient.ts +107 -20
- package/src/Api/IHttpClient.ts +17 -12
- package/src/Api/Job.ts +7 -5
- package/src/Api/Member.ts +7 -5
- package/src/Api/Model.ts +61 -14
- package/src/Api/Permission.ts +6 -5
- package/src/Api/Project.ts +93 -88
- package/src/Api/Role.ts +6 -5
- package/src/Api/User.ts +28 -17
- package/src/Api/Utils.ts +104 -0
- package/src/Api/XMLHttp.ts +72 -0
- package/src/index.ts +1 -1
- package/lib/Api/impl/Utils.d.ts +0 -32
- package/lib/Api/impl/http.d.ts +0 -66
- package/src/Api/impl/FetchError.ts +0 -48
- package/src/Api/impl/Utils.ts +0 -367
package/src/Api/User.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
24
|
import { IHttpClient } from "./IHttpClient";
|
|
25
|
-
import {
|
|
25
|
+
import { userFullName, userInitials } from "./Utils";
|
|
26
26
|
|
|
27
27
|
export interface UserParams {
|
|
28
28
|
/**
|
|
@@ -259,10 +259,12 @@ export class User {
|
|
|
259
259
|
*/
|
|
260
260
|
async checkout(): Promise<User> {
|
|
261
261
|
if (this.id === this.httpClient.signInUserId) {
|
|
262
|
-
const
|
|
262
|
+
const response = await this.httpClient.get("/user");
|
|
263
|
+
const data = await response.json();
|
|
263
264
|
this.data = { id: this.id, ...data };
|
|
264
265
|
} else {
|
|
265
|
-
const
|
|
266
|
+
const response = await this.httpClient.get(`/users/${this.id}`);
|
|
267
|
+
const data = await response.json();
|
|
266
268
|
this.data = { id: data.id, ...data.userBrief };
|
|
267
269
|
}
|
|
268
270
|
return this;
|
|
@@ -278,10 +280,12 @@ export class User {
|
|
|
278
280
|
*/
|
|
279
281
|
async update(data: any) {
|
|
280
282
|
if (this.id === this.httpClient.signInUserId) {
|
|
281
|
-
const
|
|
283
|
+
const response = await this.httpClient.put("/user", data);
|
|
284
|
+
const newData = await response.json();
|
|
282
285
|
this.data = { id: this.id, ...newData };
|
|
283
286
|
} else {
|
|
284
|
-
const
|
|
287
|
+
const response = await this.httpClient.put(`/users/${this.id}`, { userBrief: data });
|
|
288
|
+
const newData = await response.json();
|
|
285
289
|
this.data = { id: newData.id, ...newData.userBrief };
|
|
286
290
|
}
|
|
287
291
|
return this;
|
|
@@ -300,13 +304,16 @@ export class User {
|
|
|
300
304
|
* @returns Returns the raw data of a deleted user.
|
|
301
305
|
*/
|
|
302
306
|
delete(): Promise<any> {
|
|
303
|
-
return
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
307
|
+
return this.httpClient
|
|
308
|
+
.delete(`/users/${this.id}`)
|
|
309
|
+
.then((response) => response.json())
|
|
310
|
+
.then((data) => {
|
|
311
|
+
if (this.id === this.httpClient.signInUserId) {
|
|
312
|
+
this.httpClient.headers = {};
|
|
313
|
+
this.httpClient.signInUserId = "";
|
|
314
|
+
}
|
|
315
|
+
return data;
|
|
316
|
+
});
|
|
310
317
|
}
|
|
311
318
|
|
|
312
319
|
/**
|
|
@@ -334,21 +341,25 @@ export class User {
|
|
|
334
341
|
* Web API <a href="https://developer.mozilla.org/docs/Web/API/File"
|
|
335
342
|
* target="_blank">File</a> object. Setting the `image` to `null` will remove the avatar.
|
|
336
343
|
*/
|
|
337
|
-
async setAvatar(image
|
|
344
|
+
async setAvatar(image: BodyInit | null): Promise<User> {
|
|
338
345
|
if (image) {
|
|
339
346
|
if (this.id === this.httpClient.signInUserId) {
|
|
340
|
-
const
|
|
347
|
+
const response = await this.httpClient.post("/user/avatar", image);
|
|
348
|
+
const data = await response.json();
|
|
341
349
|
this.data = { id: this.id, ...data };
|
|
342
350
|
} else {
|
|
343
|
-
const
|
|
351
|
+
const response = await this.httpClient.post(`/users/${this.id}/avatar`, image);
|
|
352
|
+
const data = await response.json();
|
|
344
353
|
this.data = { id: data.id, ...data.userBrief };
|
|
345
354
|
}
|
|
346
355
|
} else {
|
|
347
356
|
if (this.id === this.httpClient.signInUserId) {
|
|
348
|
-
const
|
|
357
|
+
const response = await this.httpClient.delete("/user/avatar");
|
|
358
|
+
const data = await response.json();
|
|
349
359
|
this.data = { id: this.id, ...data };
|
|
350
360
|
} else {
|
|
351
|
-
const
|
|
361
|
+
const response = await this.httpClient.delete(`/users/${this.id}/avatar`);
|
|
362
|
+
const data = await response.json();
|
|
352
363
|
this.data = { id: data.id, ...data.userBrief };
|
|
353
364
|
}
|
|
354
365
|
}
|
package/src/Api/Utils.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
function delay(ms: number, signal: AbortSignal) {
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
let timeoutId = 0;
|
|
27
|
+
|
|
28
|
+
const abortHandler = () => {
|
|
29
|
+
clearTimeout(timeoutId);
|
|
30
|
+
resolve(true);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
timeoutId = window.setTimeout(() => {
|
|
34
|
+
signal.removeEventListener("abort", abortHandler);
|
|
35
|
+
resolve(false);
|
|
36
|
+
}, ms);
|
|
37
|
+
|
|
38
|
+
signal.addEventListener("abort", abortHandler, { once: true });
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function waitFor(
|
|
43
|
+
func: (params: any) => Promise<boolean>,
|
|
44
|
+
params: {
|
|
45
|
+
timeout?: number;
|
|
46
|
+
interval?: number;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
abortError?: DOMException;
|
|
49
|
+
timeoutError?: DOMException;
|
|
50
|
+
result?: any;
|
|
51
|
+
} = {}
|
|
52
|
+
) {
|
|
53
|
+
const timeout = params.timeout ?? 600000;
|
|
54
|
+
const interval = params.interval ?? 3000;
|
|
55
|
+
const signal = params.signal ?? new AbortController().signal;
|
|
56
|
+
const abortError = params.abortError ?? new DOMException("Aborted", "AbortError");
|
|
57
|
+
const timeoutError = params.timeoutError ?? new DOMException("Timeout", "TimeoutError");
|
|
58
|
+
|
|
59
|
+
const end = performance.now() + timeout;
|
|
60
|
+
let count = timeout / interval;
|
|
61
|
+
|
|
62
|
+
do {
|
|
63
|
+
if (await func(params)) return Promise.resolve(params.result);
|
|
64
|
+
if ((await delay(interval, signal)) || signal.aborted) return Promise.reject(abortError);
|
|
65
|
+
} while (performance.now() < end && --count > 0);
|
|
66
|
+
|
|
67
|
+
return Promise.reject(timeoutError);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function parseArgs(args: string | object): object {
|
|
71
|
+
if (typeof args === "string") {
|
|
72
|
+
const firstArg = args.indexOf("--");
|
|
73
|
+
if (firstArg !== -1) args = args.slice(firstArg);
|
|
74
|
+
const argArray = args
|
|
75
|
+
.split("--")
|
|
76
|
+
.map((x) =>
|
|
77
|
+
x
|
|
78
|
+
.split("=")
|
|
79
|
+
.map((y) => y.split(" "))
|
|
80
|
+
.flat()
|
|
81
|
+
)
|
|
82
|
+
.filter((x) => x[0])
|
|
83
|
+
.map((x) => x.concat([""]));
|
|
84
|
+
return Object.fromEntries(argArray);
|
|
85
|
+
}
|
|
86
|
+
return args ?? {};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function userFullName(firstName: string | any, lastName = "", userName = ""): string {
|
|
90
|
+
if (firstName && typeof firstName !== "string") {
|
|
91
|
+
return userFullName(firstName.firstName ?? firstName.name, firstName.lastName, firstName.userName);
|
|
92
|
+
}
|
|
93
|
+
return `${firstName ?? ""} ${lastName ?? ""}`.trim() || userName;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function userInitials(fullName = ""): string {
|
|
97
|
+
const names = fullName.split(" ").filter((x) => x);
|
|
98
|
+
return names
|
|
99
|
+
.reduce((initials, name, index) => {
|
|
100
|
+
if (index === 0 || index === names.length - 1) initials += name.charAt(0);
|
|
101
|
+
return initials;
|
|
102
|
+
}, "")
|
|
103
|
+
.toUpperCase();
|
|
104
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { FetchError, error400 } from "./FetchError";
|
|
25
|
+
|
|
26
|
+
function handleXMLHttpError(xhr: XMLHttpRequest): Promise<XMLHttpRequest> {
|
|
27
|
+
if (xhr.status === 0) {
|
|
28
|
+
return Promise.reject(new FetchError(0, "Network error"));
|
|
29
|
+
}
|
|
30
|
+
if (xhr.status < 200 || xhr.status > 299) {
|
|
31
|
+
switch (xhr.status) {
|
|
32
|
+
case 400: {
|
|
33
|
+
console.error(xhr.responseText);
|
|
34
|
+
return Promise.reject(new FetchError(400, error400(xhr.responseText)));
|
|
35
|
+
}
|
|
36
|
+
case 500: {
|
|
37
|
+
console.error(error400(xhr.responseText, xhr.responseText));
|
|
38
|
+
return Promise.reject(new FetchError(500));
|
|
39
|
+
}
|
|
40
|
+
default: {
|
|
41
|
+
return Promise.reject(new FetchError(xhr.status));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return Promise.resolve(xhr);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function $xmlhttp(
|
|
49
|
+
url: string,
|
|
50
|
+
params: {
|
|
51
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
52
|
+
headers?: HeadersInit;
|
|
53
|
+
body?: XMLHttpRequestBodyInit;
|
|
54
|
+
uploadProgress?: (progress: number) => void;
|
|
55
|
+
downloadProgress?: (progress: number) => void;
|
|
56
|
+
} = { method: "GET" }
|
|
57
|
+
): Promise<XMLHttpRequest> {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
const xhr = new XMLHttpRequest();
|
|
60
|
+
xhr.open(params.method, url, true);
|
|
61
|
+
for (const key in params.headers) {
|
|
62
|
+
xhr.setRequestHeader(key, params.headers[key]);
|
|
63
|
+
}
|
|
64
|
+
function calcProgress(event: ProgressEvent) {
|
|
65
|
+
return event.lengthComputable ? event.loaded / event.total : 1;
|
|
66
|
+
}
|
|
67
|
+
xhr.upload.onprogress = (event) => params.uploadProgress && params.uploadProgress(calcProgress(event));
|
|
68
|
+
xhr.onprogress = (event) => params.downloadProgress && params.downloadProgress(calcProgress(event));
|
|
69
|
+
xhr.onloadend = (event) => handleXMLHttpError(event.target as XMLHttpRequest).then(resolve, reject);
|
|
70
|
+
xhr.send(params.body);
|
|
71
|
+
});
|
|
72
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -33,6 +33,6 @@ export { Permission } from "./Api/Permission";
|
|
|
33
33
|
export { Project } from "./Api/Project";
|
|
34
34
|
export { Role } from "./Api/Role";
|
|
35
35
|
export { User } from "./Api/User";
|
|
36
|
-
export { parseArgs, userFullName, userInitials, waitFor } from "./Api/
|
|
36
|
+
export { parseArgs, userFullName, userInitials, waitFor } from "./Api/Utils";
|
|
37
37
|
|
|
38
38
|
export const version = "CLIENT_JS_VERSION";
|
package/lib/Api/impl/Utils.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export declare function json(request: any): any;
|
|
2
|
-
export declare function text(request: any): any;
|
|
3
|
-
export declare function arrayBuffer(request: any): any;
|
|
4
|
-
export declare function $init(method: "GET" | "POST" | "PUT" | "DELETE", headers?: HeadersInit, body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null, signal?: AbortSignal): RequestInit;
|
|
5
|
-
export declare function $fetch(url: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
6
|
-
export declare function $get(url: RequestInfo | URL, headers?: HeadersInit, signal?: AbortSignal): Promise<Response>;
|
|
7
|
-
export declare function $put(url: RequestInfo | URL, headers?: HeadersInit, body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null): Promise<Response>;
|
|
8
|
-
export declare function $post(url: RequestInfo | URL, headers?: HeadersInit, body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null): Promise<Response>;
|
|
9
|
-
export declare function $delete(url: RequestInfo | URL, headers?: HeadersInit): Promise<Response>;
|
|
10
|
-
export declare function streamProgress(stream: ReadableStream<Uint8Array>, onprogress: (progress: number) => void): ReadableStream<Uint8Array>;
|
|
11
|
-
export declare function downloadProgress(response: Response, onprogress?: (progress: number) => void): Response;
|
|
12
|
-
interface XMLHttpParams {
|
|
13
|
-
headers: HeadersInit;
|
|
14
|
-
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
15
|
-
body?: XMLHttpRequestBodyInit | Document;
|
|
16
|
-
uploadProgress?: (progress: number) => void;
|
|
17
|
-
downloadProgress?: (progress: number) => void;
|
|
18
|
-
}
|
|
19
|
-
export declare function $XMLHttp(url: string, { headers, method, body, uploadProgress, downloadProgress }: XMLHttpParams): Promise<XMLHttpRequest>;
|
|
20
|
-
export declare function waitFor(func: (params: any) => Promise<boolean>, params?: {
|
|
21
|
-
timeout?: number;
|
|
22
|
-
interval?: number;
|
|
23
|
-
signal?: AbortSignal;
|
|
24
|
-
abortError?: DOMException;
|
|
25
|
-
timeoutError?: DOMException;
|
|
26
|
-
result?: any;
|
|
27
|
-
}): Promise<any>;
|
|
28
|
-
export declare function downloadPartOfFile(requestId: number, records: any | null, url: string, defHeaders: HeadersInit, onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<void>;
|
|
29
|
-
export declare function parseArgs(args: string | object): object;
|
|
30
|
-
export declare function userFullName(firstName: string | any, lastName?: string, userName?: string): string;
|
|
31
|
-
export declare function userInitials(fullName?: string): string;
|
|
32
|
-
export {};
|
package/lib/Api/impl/http.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export declare const STATUS_CODES: {
|
|
2
|
-
100: string;
|
|
3
|
-
101: string;
|
|
4
|
-
102: string;
|
|
5
|
-
103: string;
|
|
6
|
-
200: string;
|
|
7
|
-
201: string;
|
|
8
|
-
202: string;
|
|
9
|
-
203: string;
|
|
10
|
-
204: string;
|
|
11
|
-
205: string;
|
|
12
|
-
206: string;
|
|
13
|
-
207: string;
|
|
14
|
-
208: string;
|
|
15
|
-
226: string;
|
|
16
|
-
300: string;
|
|
17
|
-
301: string;
|
|
18
|
-
302: string;
|
|
19
|
-
303: string;
|
|
20
|
-
304: string;
|
|
21
|
-
305: string;
|
|
22
|
-
307: string;
|
|
23
|
-
308: string;
|
|
24
|
-
400: string;
|
|
25
|
-
401: string;
|
|
26
|
-
402: string;
|
|
27
|
-
403: string;
|
|
28
|
-
404: string;
|
|
29
|
-
405: string;
|
|
30
|
-
406: string;
|
|
31
|
-
407: string;
|
|
32
|
-
408: string;
|
|
33
|
-
409: string;
|
|
34
|
-
410: string;
|
|
35
|
-
411: string;
|
|
36
|
-
412: string;
|
|
37
|
-
413: string;
|
|
38
|
-
414: string;
|
|
39
|
-
415: string;
|
|
40
|
-
416: string;
|
|
41
|
-
417: string;
|
|
42
|
-
418: string;
|
|
43
|
-
421: string;
|
|
44
|
-
422: string;
|
|
45
|
-
423: string;
|
|
46
|
-
424: string;
|
|
47
|
-
425: string;
|
|
48
|
-
426: string;
|
|
49
|
-
428: string;
|
|
50
|
-
429: string;
|
|
51
|
-
431: string;
|
|
52
|
-
451: string;
|
|
53
|
-
500: string;
|
|
54
|
-
501: string;
|
|
55
|
-
502: string;
|
|
56
|
-
503: string;
|
|
57
|
-
504: string;
|
|
58
|
-
505: string;
|
|
59
|
-
506: string;
|
|
60
|
-
507: string;
|
|
61
|
-
508: string;
|
|
62
|
-
509: string;
|
|
63
|
-
510: string;
|
|
64
|
-
511: string;
|
|
65
|
-
};
|
|
66
|
-
export declare function statusText(status: number): string;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
|
|
3
|
-
// All rights reserved.
|
|
4
|
-
//
|
|
5
|
-
// This software and its documentation and related materials are owned by
|
|
6
|
-
// the Alliance. The software may only be incorporated into application
|
|
7
|
-
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
-
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
-
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
-
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
-
// protected by copyright law and international treaty provisions. Application
|
|
12
|
-
// programs incorporating this software must include the following statement
|
|
13
|
-
// with their copyright notices:
|
|
14
|
-
//
|
|
15
|
-
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
-
// license agreement with Open Design Alliance.
|
|
17
|
-
// Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
|
|
18
|
-
// All rights reserved.
|
|
19
|
-
//
|
|
20
|
-
// By use of this software, its documentation or related materials, you
|
|
21
|
-
// acknowledge and accept the above terms.
|
|
22
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
-
|
|
24
|
-
import { statusText } from "./http";
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The `FetchError` object indicates an error when request to Open Cloud Server could not be
|
|
28
|
-
* performed. A `FetchError` is typically (but not exclusively) thrown when a network error
|
|
29
|
-
* occurs, access denied, or object not found.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
export class FetchError extends Error {
|
|
33
|
-
protected status: number;
|
|
34
|
-
protected statusText: string;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @property status - The <a href="https://developer.mozilla.org/docs/Web/HTTP/Status" target
|
|
38
|
-
* ="_blank">HTTP status code</a> of the response.
|
|
39
|
-
* @property message - Error message. Inherited from <a
|
|
40
|
-
* href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error"
|
|
41
|
-
* target ="_blank">Error</a>.
|
|
42
|
-
*/
|
|
43
|
-
constructor(status: number, message?: string) {
|
|
44
|
-
super(message || statusText(status));
|
|
45
|
-
this.status = status;
|
|
46
|
-
this.statusText = statusText(status);
|
|
47
|
-
}
|
|
48
|
-
}
|