@nestia/fetcher 1.0.1 → 1.1.0-dev.20230414
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/Fetcher.d.ts +4 -0
- package/lib/Fetcher.js +3 -1
- package/lib/Fetcher.js.map +1 -1
- 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/Fetcher.ts +10 -1
- package/src/HttpError.ts +41 -0
package/lib/Fetcher.d.ts
CHANGED
package/lib/Fetcher.js
CHANGED
|
@@ -119,7 +119,9 @@ var Fetcher = /** @class */ (function () {
|
|
|
119
119
|
if (!body)
|
|
120
120
|
return [2 /*return*/, undefined];
|
|
121
121
|
// CHECK THE STATUS CODE
|
|
122
|
-
if (response.status !==
|
|
122
|
+
if (response.status !== encrypted.status &&
|
|
123
|
+
response.status !== 200 &&
|
|
124
|
+
response.status !== 201)
|
|
123
125
|
throw new HttpError_1.HttpError(method, path, response.status, body);
|
|
124
126
|
// FINALIZATION (WITH DECODING)
|
|
125
127
|
if (encrypted.response === true) {
|
package/lib/Fetcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../src/Fetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AAM9B,uCAAsC;AACtC,yCAAwC;AACxC,kDAAiD;AAEjD;;;;;;;;;;;;;GAaG;AACH;IAAA;
|
|
1
|
+
{"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../src/Fetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AAM9B,uCAAsC;AACtC,yCAAwC;AACxC,kDAAiD;AAEjD;;;;;;;;;;;;;GAaG;AACH;IAAA;IA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CAAA;gBAAW,qBAAM,IAAA,iBAAO,EAAC,YAAY,CAAC,EAAA;;gBAA5C,GAAO,KAAK,GAAI,CAAC,SAA2B,CAAS,CAAC,OAAO,CAAC;;oBAClE,sBAAQ,MAAc,CAAC,KAAK,EAAC;oBAEjC,sBAAO,MAAM,CAAC,KAAK,EAAC;;;KACvB,CAAC,CAAC;AAEH,SAAS,WAAW,CAChB,QAA6B,EAC7B,OAA0C,EAC1C,IAAY,EACZ,OAAgB;IAEhB,IAAI,QAAQ,CAAC,QAAQ,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAClD,IAAI,OAAO,QAAQ,CAAC,QAAQ,KAAK,UAAU;QACvC,OAAO,QAAQ,CAAC,QAAQ,CACpB;YACI,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;YACtB,IAAI,MAAA;SACP,EACD,OAAO,CACV,CAAC;IACN,OAAO,QAAQ,CAAC,QAAQ,CAAC;AAC7B,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAgB;IACvC,IAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,OAAO,CAAC,OAAO,CAAC,UAAC,KAAK,EAAE,GAAG,IAAK,OAAA,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,EAArB,CAAqB,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
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/Fetcher.ts
CHANGED
|
@@ -129,7 +129,11 @@ export class Fetcher {
|
|
|
129
129
|
if (!body) return undefined!;
|
|
130
130
|
|
|
131
131
|
// CHECK THE STATUS CODE
|
|
132
|
-
if (
|
|
132
|
+
if (
|
|
133
|
+
response.status !== encrypted.status &&
|
|
134
|
+
response.status !== 200 &&
|
|
135
|
+
response.status !== 201
|
|
136
|
+
)
|
|
133
137
|
throw new HttpError(method, path, response.status, body);
|
|
134
138
|
|
|
135
139
|
// FINALIZATION (WITH DECODING)
|
|
@@ -199,6 +203,11 @@ export namespace Fetcher {
|
|
|
199
203
|
* Whether the response body be encrypted or not.
|
|
200
204
|
*/
|
|
201
205
|
response: boolean;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* When special status code is allowed.
|
|
209
|
+
*/
|
|
210
|
+
status?: number;
|
|
202
211
|
}
|
|
203
212
|
}
|
|
204
213
|
|
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;
|