@nestia/fetcher 1.0.1 → 1.1.0-dev.20230413
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/lib/HttpError.d.ts +25 -0
- package/lib/HttpError.js +28 -0
- package/lib/HttpError.js.map +1 -1
- package/package.json +1 -1
- package/src/HttpError.ts +41 -0
package/lib/HttpError.d.ts
CHANGED
|
@@ -18,4 +18,29 @@ export declare class HttpError extends Error {
|
|
|
18
18
|
* @param message Error message from the remote HTTP server.
|
|
19
19
|
*/
|
|
20
20
|
constructor(method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH", path: string, status: number, message: string);
|
|
21
|
+
/**
|
|
22
|
+
* `HttpError` to JSON.
|
|
23
|
+
*
|
|
24
|
+
* When you call `JSON.stringify()` function on current `HttpError` instance,
|
|
25
|
+
* this `HttpError.toJSON()` method would be automatically called.
|
|
26
|
+
*
|
|
27
|
+
* Also, if response body from the remote HTTP server forms a JSON object,
|
|
28
|
+
* this `HttpError.toJSON()` method would be useful because it returns the
|
|
29
|
+
* parsed JSON object about the {@link message} property.
|
|
30
|
+
*
|
|
31
|
+
* @template T Expected type of the response body.
|
|
32
|
+
* @returns JSON object of the `HttpError`.
|
|
33
|
+
*/
|
|
34
|
+
toJSON<T>(): HttpError.IProps<T>;
|
|
35
|
+
}
|
|
36
|
+
export declare namespace HttpError {
|
|
37
|
+
/**
|
|
38
|
+
* Returned type of {@link HttpError.toJSON} method.
|
|
39
|
+
*/
|
|
40
|
+
interface IProps<T> {
|
|
41
|
+
method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH";
|
|
42
|
+
path: string;
|
|
43
|
+
status: number;
|
|
44
|
+
message: T;
|
|
45
|
+
}
|
|
21
46
|
}
|
package/lib/HttpError.js
CHANGED
|
@@ -39,6 +39,10 @@ var HttpError = /** @class */ (function (_super) {
|
|
|
39
39
|
_this.method = method;
|
|
40
40
|
_this.path = path;
|
|
41
41
|
_this.status = status;
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
_this.body_ = NOT_YET;
|
|
42
46
|
// INHERITANCE POLYFILL
|
|
43
47
|
var proto = _newTarget.prototype;
|
|
44
48
|
if (Object.setPrototypeOf)
|
|
@@ -47,7 +51,31 @@ var HttpError = /** @class */ (function (_super) {
|
|
|
47
51
|
_this.__proto__ = proto;
|
|
48
52
|
return _this;
|
|
49
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* `HttpError` to JSON.
|
|
56
|
+
*
|
|
57
|
+
* When you call `JSON.stringify()` function on current `HttpError` instance,
|
|
58
|
+
* this `HttpError.toJSON()` method would be automatically called.
|
|
59
|
+
*
|
|
60
|
+
* Also, if response body from the remote HTTP server forms a JSON object,
|
|
61
|
+
* this `HttpError.toJSON()` method would be useful because it returns the
|
|
62
|
+
* parsed JSON object about the {@link message} property.
|
|
63
|
+
*
|
|
64
|
+
* @template T Expected type of the response body.
|
|
65
|
+
* @returns JSON object of the `HttpError`.
|
|
66
|
+
*/
|
|
67
|
+
HttpError.prototype.toJSON = function () {
|
|
68
|
+
if (this.body_ === NOT_YET)
|
|
69
|
+
this.body_ = JSON.parse(this.message);
|
|
70
|
+
return {
|
|
71
|
+
method: this.method,
|
|
72
|
+
path: this.path,
|
|
73
|
+
status: this.status,
|
|
74
|
+
message: this.body_,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
50
77
|
return HttpError;
|
|
51
78
|
}(Error));
|
|
52
79
|
exports.HttpError = HttpError;
|
|
80
|
+
var NOT_YET = {};
|
|
53
81
|
//# sourceMappingURL=HttpError.js.map
|
package/lib/HttpError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../src/HttpError.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH;IAA+B,6BAAK;
|
|
1
|
+
{"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../src/HttpError.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH;IAA+B,6BAAK;IAMhC;;;;;;;OAOG;IACH,mBACoB,MAAmD,EACnD,IAAY,EACZ,MAAc,EAC9B,OAAe;;QAJnB,YAMI,kBAAM,OAAO,CAAC,SAMjB;QAXmB,YAAM,GAAN,MAAM,CAA6C;QACnD,UAAI,GAAJ,IAAI,CAAQ;QACZ,YAAM,GAAN,MAAM,CAAQ;QAhBlC;;WAEG;QACK,WAAK,GAAQ,OAAO,CAAC;QAkBzB,uBAAuB;QACvB,IAAM,KAAK,GAAc,WAAW,SAAS,CAAC;QAC9C,IAAI,MAAM,CAAC,cAAc;YAAE,MAAM,CAAC,cAAc,CAAC,KAAI,EAAE,KAAK,CAAC,CAAC;;YACxD,KAAY,CAAC,SAAS,GAAG,KAAK,CAAC;;IACzC,CAAC;IAED;;;;;;;;;;;;OAYG;IACI,0BAAM,GAAb;QACI,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO;YAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClE,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,KAAK;SACtB,CAAC;IACN,CAAC;IACL,gBAAC;AAAD,CAAC,AAlDD,CAA+B,KAAK,GAkDnC;AAlDY,8BAAS;AA+DtB,IAAM,OAAO,GAAG,EAAS,CAAC"}
|
package/package.json
CHANGED
package/src/HttpError.ts
CHANGED
|
@@ -6,6 +6,11 @@
|
|
|
6
6
|
* @author Jeongho Nam - https://github.com/samchon
|
|
7
7
|
*/
|
|
8
8
|
export class HttpError extends Error {
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
private body_: any = NOT_YET;
|
|
13
|
+
|
|
9
14
|
/**
|
|
10
15
|
* Initializer Constructor.
|
|
11
16
|
*
|
|
@@ -27,4 +32,40 @@ export class HttpError extends Error {
|
|
|
27
32
|
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
28
33
|
else (this as any).__proto__ = proto;
|
|
29
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* `HttpError` to JSON.
|
|
38
|
+
*
|
|
39
|
+
* When you call `JSON.stringify()` function on current `HttpError` instance,
|
|
40
|
+
* this `HttpError.toJSON()` method would be automatically called.
|
|
41
|
+
*
|
|
42
|
+
* Also, if response body from the remote HTTP server forms a JSON object,
|
|
43
|
+
* this `HttpError.toJSON()` method would be useful because it returns the
|
|
44
|
+
* parsed JSON object about the {@link message} property.
|
|
45
|
+
*
|
|
46
|
+
* @template T Expected type of the response body.
|
|
47
|
+
* @returns JSON object of the `HttpError`.
|
|
48
|
+
*/
|
|
49
|
+
public toJSON<T>(): HttpError.IProps<T> {
|
|
50
|
+
if (this.body_ === NOT_YET) this.body_ = JSON.parse(this.message);
|
|
51
|
+
return {
|
|
52
|
+
method: this.method,
|
|
53
|
+
path: this.path,
|
|
54
|
+
status: this.status,
|
|
55
|
+
message: this.body_,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
30
58
|
}
|
|
59
|
+
export namespace HttpError {
|
|
60
|
+
/**
|
|
61
|
+
* Returned type of {@link HttpError.toJSON} method.
|
|
62
|
+
*/
|
|
63
|
+
export interface IProps<T> {
|
|
64
|
+
method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH";
|
|
65
|
+
path: string;
|
|
66
|
+
status: number;
|
|
67
|
+
message: T;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const NOT_YET = {} as any;
|