Skip to content

Commit 4540ac6

Browse files
author
Adrien Maret
authored
Add props in KuzzleError (#696)
## What does this PR do ? Kuzzle returns a `props` property with error, this property contains all the string used to build the error message. Those string can be used by the application layer to build other error messages. This PR expose this property
1 parent c6636e3 commit 4540ac6

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

doc/7/core-classes/kuzzle-error/properties/index.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ order: 10
99

1010
# Properties
1111

12-
| Property name | Type | Description |
13-
|---------------|-------------------|------------------------------------------------------------------------------------------------------|
14-
| `kuzzleStack` | <pre>string</pre> | Kuzzle stacktrace (only in development mode) |
15-
| `message` | <pre>string</pre> | Error message |
16-
| `status` | <pre>number</pre> | Error status code |
17-
| `stack` | <pre>string</pre> | Complete error stacktrace (Kuzzle + SDK) (only in development mode) |
18-
| `id` | <pre>string</pre> | Error unique identifier |
19-
| `code` | <pre>string</pre> | Error unique code |
20-
| `controller` | <pre>string</pre> | API controller name |
21-
| `action` | <pre>string</pre> | API action name |
22-
| `volatile` | <pre>object</pre> | KuzzleRequest [volatile data](https://docs.kuzzle.io/core/2/guides/main-concepts/api/#volatile-data) |
23-
| `index` | <pre>string</pre> | Index name |
24-
| `collection` | <pre>string</pre> | Collection name name |
25-
| `requestId` | <pre>string</pre> | request id name |
26-
| `_id` | <pre>string</pre> | Document unique identifier |
27-
| `count` | <pre>number</pre> | Number of associated errors (PartialError only) |
12+
| Property name | Type | Description |
13+
| ------------- | ------------------- | ---------------------------------------------------------------------------------------------------- |
14+
| `kuzzleStack` | <pre>string</pre> | Kuzzle stacktrace (only in development mode) |
15+
| `message` | <pre>string</pre> | Error message |
16+
| `props` | <pre>string[]</pre> | Placeholders used to construct the error message |
17+
| `status` | <pre>number</pre> | Error status code |
18+
| `stack` | <pre>string</pre> | Complete error stacktrace (Kuzzle + SDK) (only in development mode) |
19+
| `id` | <pre>string</pre> | Error unique identifier |
20+
| `code` | <pre>string</pre> | Error unique code |
21+
| `controller` | <pre>string</pre> | API controller name |
22+
| `action` | <pre>string</pre> | API action name |
23+
| `volatile` | <pre>object</pre> | KuzzleRequest [volatile data](https://docs.kuzzle.io/core/2/guides/main-concepts/api/#volatile-data) |
24+
| `index` | <pre>string</pre> | Index name |
25+
| `collection` | <pre>string</pre> | Collection name name |
26+
| `requestId` | <pre>string</pre> | request id name |
27+
| `_id` | <pre>string</pre> | Document unique identifier |
28+
| `count` | <pre>number</pre> | Number of associated errors (PartialError only) |

src/KuzzleError.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ export class KuzzleError extends Error {
7777
*/
7878
public count?: number;
7979

80+
/**
81+
* Placeholders used to construct the error message
82+
*/
83+
public props?: string[];
84+
8085
/**
8186
* This class represents a Kuzzle API error.
8287
* The SDK stack is needed alongside the protocol used.
@@ -98,7 +103,7 @@ export class KuzzleError extends Error {
98103
at processTicksAndRejections (internal/process/task_queues.js:97:5)
99104
*/
100105
constructor (
101-
apiError: { message: string, status?: number, id?: string, code?: number, errors?: JSONObject[], count?: number, stack?: string },
106+
apiError: { message: string, status?: number, id?: string, code?: number, errors?: JSONObject[], count?: number, stack?: string, props?: string[] },
102107
sdkStack?: string,
103108
protocol?: string,
104109
request?: RequestPayload,
@@ -108,6 +113,7 @@ export class KuzzleError extends Error {
108113
this.status = apiError.status;
109114
this.id = apiError.id;
110115
this.code = apiError.code;
116+
this.props = apiError.props;
111117

112118
if (request) {
113119
this.controller = request.controller;

0 commit comments

Comments
 (0)