@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.42.1",
3
+ "version": "3.43.0",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -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 { 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";
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 { RestAPI };
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 Error(`the data cannot be ${key} (response ${resp.status})`);
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 Error(`the response does not contain a valid json (actual: ${body}).`);
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)) {
@@ -142,7 +142,7 @@ function getMonsterVersion() {
142
142
  }
143
143
 
144
144
  /** don't touch, replaced by make with package.json version */
145
- monsterVersion = new Version("3.42.1");
145
+ monsterVersion = new Version("3.43.0");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.42.1")
10
+ monsterVersion = new Version("3.43.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13