@nestia/fetcher
Advanced tools
Comparing version 1.0.1 to 1.1.0-dev.20230413
@@ -21,2 +21,27 @@ /** | ||
constructor(method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH", path: string, status: number, message: string); | ||
/** | ||
* `HttpError` to JSON. | ||
* | ||
* When you call `JSON.stringify()` function on current `HttpError` instance, | ||
* this `HttpError.toJSON()` method would be automatically called. | ||
* | ||
* Also, if response body from the remote HTTP server forms a JSON object, | ||
* this `HttpError.toJSON()` method would be useful because it returns the | ||
* parsed JSON object about the {@link message} property. | ||
* | ||
* @template T Expected type of the response body. | ||
* @returns JSON object of the `HttpError`. | ||
*/ | ||
toJSON<T>(): HttpError.IProps<T>; | ||
} | ||
export declare namespace HttpError { | ||
/** | ||
* Returned type of {@link HttpError.toJSON} method. | ||
*/ | ||
interface IProps<T> { | ||
method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH"; | ||
path: string; | ||
status: number; | ||
message: T; | ||
} | ||
} |
@@ -42,2 +42,6 @@ "use strict"; | ||
_this.status = status; | ||
/** | ||
* @internal | ||
*/ | ||
_this.body_ = NOT_YET; | ||
// INHERITANCE POLYFILL | ||
@@ -51,5 +55,29 @@ var proto = _newTarget.prototype; | ||
} | ||
/** | ||
* `HttpError` to JSON. | ||
* | ||
* When you call `JSON.stringify()` function on current `HttpError` instance, | ||
* this `HttpError.toJSON()` method would be automatically called. | ||
* | ||
* Also, if response body from the remote HTTP server forms a JSON object, | ||
* this `HttpError.toJSON()` method would be useful because it returns the | ||
* parsed JSON object about the {@link message} property. | ||
* | ||
* @template T Expected type of the response body. | ||
* @returns JSON object of the `HttpError`. | ||
*/ | ||
HttpError.prototype.toJSON = function () { | ||
if (this.body_ === NOT_YET) | ||
this.body_ = JSON.parse(this.message); | ||
return { | ||
method: this.method, | ||
path: this.path, | ||
status: this.status, | ||
message: this.body_, | ||
}; | ||
}; | ||
return HttpError; | ||
}(Error)); | ||
exports.HttpError = HttpError; | ||
var NOT_YET = {}; | ||
//# sourceMappingURL=HttpError.js.map |
{ | ||
"name": "@nestia/fetcher", | ||
"version": "1.0.1", | ||
"version": "1.1.0-dev.20230413", | ||
"description": "Fetcher library of Nestia SDK", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -10,2 +10,7 @@ /** | ||
/** | ||
* @internal | ||
*/ | ||
private body_: any = NOT_YET; | ||
/** | ||
* Initializer Constructor. | ||
@@ -31,2 +36,38 @@ * | ||
} | ||
/** | ||
* `HttpError` to JSON. | ||
* | ||
* When you call `JSON.stringify()` function on current `HttpError` instance, | ||
* this `HttpError.toJSON()` method would be automatically called. | ||
* | ||
* Also, if response body from the remote HTTP server forms a JSON object, | ||
* this `HttpError.toJSON()` method would be useful because it returns the | ||
* parsed JSON object about the {@link message} property. | ||
* | ||
* @template T Expected type of the response body. | ||
* @returns JSON object of the `HttpError`. | ||
*/ | ||
public toJSON<T>(): HttpError.IProps<T> { | ||
if (this.body_ === NOT_YET) this.body_ = JSON.parse(this.message); | ||
return { | ||
method: this.method, | ||
path: this.path, | ||
status: this.status, | ||
message: this.body_, | ||
}; | ||
} | ||
} | ||
export namespace HttpError { | ||
/** | ||
* Returned type of {@link HttpError.toJSON} method. | ||
*/ | ||
export interface IProps<T> { | ||
method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH"; | ||
path: string; | ||
status: number; | ||
message: T; | ||
} | ||
} | ||
const NOT_YET = {} as any; |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
60329
1174
1