@schukai/monster 3.42.1 → 3.43.0
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright schukai GmbH and contributors 2023. All Rights Reserved.
|
3
|
+
* Node module: @schukai/monster
|
4
|
+
* This file is licensed under the AGPLv3 License.
|
5
|
+
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
|
+
*/
|
7
|
+
|
8
|
+
import { internalSymbol, instanceSymbol } from "../../../../constants.mjs";
|
9
|
+
|
10
|
+
export { DataFetchError };
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Error message for API requests
|
14
|
+
*
|
15
|
+
* @license AGPLv3
|
16
|
+
* @since 3.43.0
|
17
|
+
* @copyright schukai GmbH
|
18
|
+
* @memberOf Monster.Data.Datasource.Server.RestAPI
|
19
|
+
* @summary the error is thrown by the rest api in case of error
|
20
|
+
*/
|
21
|
+
class DataFetchError extends Error {
|
22
|
+
/**
|
23
|
+
*
|
24
|
+
* @param {string} message
|
25
|
+
* @param {Response} response
|
26
|
+
*/
|
27
|
+
constructor(message, response) {
|
28
|
+
super(message);
|
29
|
+
this[internalSymbol] = {
|
30
|
+
response: response
|
31
|
+
};
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* This method is called by the `instanceof` operator.
|
36
|
+
* @returns {symbol}
|
37
|
+
* @since 2.1.0
|
38
|
+
*/
|
39
|
+
static get [instanceSymbol]() {
|
40
|
+
return Symbol.for("@schukai/monster/data/datasource/server/restapi/datafetcherror@@instance");
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* @return {Response}
|
45
|
+
*/
|
46
|
+
getResponse() {
|
47
|
+
return this[internalSymbol]["response"];
|
48
|
+
}
|
49
|
+
|
50
|
+
}
|
@@ -5,12 +5,13 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
import {
|
11
|
-
import {
|
8
|
+
import {internalSymbol, instanceSymbol} from "../../../constants.mjs";
|
9
|
+
import {isObject, isFunction} from "../../../types/is.mjs";
|
10
|
+
import {Server} from "../server.mjs";
|
11
|
+
import {WriteError} from "./restapi/writeerror.mjs";
|
12
|
+
import {DataFetchError} from "./restapi/data-fetch-error.mjs";
|
12
13
|
|
13
|
-
export {
|
14
|
+
export {RestAPI};
|
14
15
|
|
15
16
|
/**
|
16
17
|
* @type {symbol}
|
@@ -188,7 +189,7 @@ function fetchData(init, key, callback) {
|
|
188
189
|
const acceptedStatus = self.getOption(`${key}.acceptedStatus`, [200]);
|
189
190
|
|
190
191
|
if (acceptedStatus.indexOf(resp.status) === -1) {
|
191
|
-
throw
|
192
|
+
throw new DataFetchError(`the response does not contain a accepted status (actual: ${resp.status}).`, response);
|
192
193
|
}
|
193
194
|
|
194
195
|
return resp.text();
|
@@ -205,7 +206,7 @@ function fetchData(init, key, callback) {
|
|
205
206
|
body = `${body.substring(0, 97)}...`;
|
206
207
|
}
|
207
208
|
|
208
|
-
throw new
|
209
|
+
throw new DataFetchError(`the response does not contain a valid json (actual: ${body}).`, response);
|
209
210
|
}
|
210
211
|
|
211
212
|
if (callback && isFunction(callback)) {
|
package/source/types/version.mjs
CHANGED
package/test/cases/monster.mjs
CHANGED