@aptly-as/sdk-nodejs 0.2.2 → 0.2.5

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/README.md CHANGED
@@ -1,15 +1,15 @@
1
- # Aptly web sdk
2
-
3
- SDK library for Node.js libraries.
4
-
5
- ## Installation
6
- ```
7
- pnpm install
8
- pnpm dev
9
- ```
10
-
11
- ## Code
12
-
13
- ### AptlyResponseError
14
- Handle errors for backend. Create simple to more complex errors with provided functions.\
1
+ # Aptly web sdk
2
+
3
+ SDK library for Node.js libraries.
4
+
5
+ ## Installation
6
+ ```
7
+ pnpm install
8
+ pnpm dev
9
+ ```
10
+
11
+ ## Code
12
+
13
+ ### AptlyResponseError
14
+ Handle errors for backend. Create simple to more complex errors with provided functions.\
15
15
  Use `toJSON` to return a nice formated error to frontend.
@@ -16,7 +16,7 @@ export class AptlyResponseError extends Error {
16
16
  status: 500,
17
17
  name: ERROR_NAME,
18
18
  props: {
19
- code: AptlyErrorCode.Default,
19
+ code: AptlyErrorCode.Error,
20
20
  level: AptlyLogLevel.Error,
21
21
  errors: [],
22
22
  detail: '',
@@ -40,7 +40,7 @@ export class AptlyResponseError extends Error {
40
40
  return this.props.errors || [];
41
41
  }
42
42
  get code() {
43
- return this.props.code || AptlyErrorCode.Default;
43
+ return this.props.code || AptlyErrorCode.Error;
44
44
  }
45
45
  get link() {
46
46
  return this.props.link || '';
@@ -56,25 +56,29 @@ export class AptlyResponseError extends Error {
56
56
  return this;
57
57
  }
58
58
  toJSON(simple) {
59
+ const link = this.props.link || '';
60
+ const detail = this.props.detail || '';
61
+ const code = this.props.code || AptlyErrorCode.Error;
62
+ const errors = this.props.errors ? this.props.errors.map((x) => x.toJSON(true)) : [];
59
63
  if (simple) {
60
64
  return {
61
- code: this.code,
65
+ code,
62
66
  title: this.message,
63
67
  message: this.message,
64
- detail: this.detail,
65
- link: this.link,
68
+ detail,
69
+ link,
66
70
  };
67
71
  }
68
72
  return {
69
73
  name: this.name,
70
74
  id: this._id,
71
75
  status: this.status,
72
- code: this.code,
73
76
  title: this.message,
74
77
  message: this.message,
75
- detail: this.detail,
76
- link: this.link,
77
- errors: this.errors.map((x) => x.toJSON(true)),
78
+ code,
79
+ detail,
80
+ link,
81
+ errors,
78
82
  };
79
83
  }
80
84
  log() {
@@ -82,7 +86,10 @@ export class AptlyResponseError extends Error {
82
86
  return this;
83
87
  }
84
88
  toString() {
85
- return `${this.message}: ${this.detail}`;
89
+ if (this.detail) {
90
+ return `${this.message}: ${this.detail}`;
91
+ }
92
+ return this.message;
86
93
  }
87
94
  res(_request, _response) {
88
95
  throw new Error('AptlyResponseError res function has not been implemented.');
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@aptly-as/sdk-nodejs",
3
- "version": "0.2.2",
3
+ "version": "0.2.5",
4
4
  "description": "Aptly SDK library for node.js applications",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "author": "Emil Andreas Olsen <emil@aptly.as>",
8
8
  "license": "ISC",
9
9
  "devDependencies": {
10
- "@aptly-as/types": "^2.7.15",
10
+ "@aptly-as/types": "^2.9.2",
11
11
  "@vitest/ui": "^2.1.8",
12
12
  "husky": "^9.1.7",
13
- "lint-staged": "^15.2.11",
13
+ "lint-staged": "^15.5.2",
14
14
  "mongoose": "^8.9.5",
15
- "prettier": "^3.4.2",
16
- "typescript": "^5.7.2",
17
- "vitest": "^2.1.8"
15
+ "prettier": "^3.8.1",
16
+ "typescript": "^5.9.3",
17
+ "vitest": "^4.0.18"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@aptly-as/types": "*",
@@ -1,8 +1,8 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "include": ["lib"],
4
- "files": [
5
- "lib/index.ts"
6
- ],
7
- "exclude": ["node_modules", "test", "lib/**/*.test.ts"]
8
- }
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["lib"],
4
+ "files": [
5
+ "lib/index.ts"
6
+ ],
7
+ "exclude": ["node_modules", "test", "lib/**/*.test.ts"]
8
+ }