Skip to content

Commit 31312a3

Browse files
committed
feat: allow additional metadata on ServiceErrors to clients
1 parent 98c23da commit 31312a3

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"request-ip": "^3.3.0"
9191
},
9292
"devDependencies": {
93-
"@commitlint/cli": "^19.3.0",
93+
"@commitlint/cli": "^19.4.0",
9494
"@commitlint/config-conventional": "^19.2.2",
9595
"@openapi-typescript-infra/coconfig": "^4.4.0",
9696
"@semantic-release/commit-analyzer": "^13.0.0",

src/error.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface ServiceErrorSpec {
88
display_message?: string;
99
log_stack?: boolean;
1010
expected_error?: boolean;
11+
client_metadata?: Record<string, unknown>;
1112
}
1213

1314
/**
@@ -30,6 +31,9 @@ export class ServiceError<
3031

3132
public log_stack?: boolean;
3233

34+
// Additional data TO BE RETURNED TO THE CLIENT
35+
public client_metadata?: Record<string, unknown>;
36+
3337
// If true, this shouldn't be logged as an error, but as an info log.
3438
// This is common when the error needs to go to the client, but should not
3539
// take up the valuable mental space of an error log.

src/telemetry/requestLogger.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export function errorHandlerMiddleware<
198198
domain: body.domain,
199199
code: body.code,
200200
display_message: body.display_message,
201+
...loggable.client_metadata,
201202
};
202203
}
203204
// Set the status to error, even if we aren't going to render the error.
@@ -211,6 +212,7 @@ export function errorHandlerMiddleware<
211212
message: loggable.message,
212213
domain: loggable.domain,
213214
display_message: loggable.display_message,
215+
...loggable.client_metadata,
214216
});
215217
} else {
216218
next(error);

yarn.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ __metadata:
6161
languageName: node
6262
linkType: hard
6363

64-
"@commitlint/cli@npm:^19.3.0":
65-
version: 19.3.0
66-
resolution: "@commitlint/cli@npm:19.3.0"
64+
"@commitlint/cli@npm:^19.4.0":
65+
version: 19.4.0
66+
resolution: "@commitlint/cli@npm:19.4.0"
6767
dependencies:
6868
"@commitlint/format": ^19.3.0
6969
"@commitlint/lint": ^19.2.2
70-
"@commitlint/load": ^19.2.0
71-
"@commitlint/read": ^19.2.1
70+
"@commitlint/load": ^19.4.0
71+
"@commitlint/read": ^19.4.0
7272
"@commitlint/types": ^19.0.3
7373
execa: ^8.0.1
7474
yargs: ^17.0.0
7575
bin:
7676
commitlint: cli.js
77-
checksum: 2329756f6e3313948aafac378b2cf2fe3b436c8dd0260e517b68dd7e7c52e944d280e562f93c91308c13d60461af469641c031bae09131aa34a953e2f7074c29
77+
checksum: fa433a633eef67905dc7f8e3a5e1a2b97eb54d829e7c0919592f3d8707ef8155e3e32970675e6022997cf2b521460cc4ca3d4babfb79aa1e69655fb71ebda3a6
7878
languageName: node
7979
linkType: hard
8080

@@ -151,9 +151,9 @@ __metadata:
151151
languageName: node
152152
linkType: hard
153153

154-
"@commitlint/load@npm:^19.2.0":
155-
version: 19.2.0
156-
resolution: "@commitlint/load@npm:19.2.0"
154+
"@commitlint/load@npm:^19.4.0":
155+
version: 19.4.0
156+
resolution: "@commitlint/load@npm:19.4.0"
157157
dependencies:
158158
"@commitlint/config-validator": ^19.0.3
159159
"@commitlint/execute-rule": ^19.0.0
@@ -165,7 +165,7 @@ __metadata:
165165
lodash.isplainobject: ^4.0.6
166166
lodash.merge: ^4.6.2
167167
lodash.uniq: ^4.5.0
168-
checksum: 5cd35a0a60064c70c06ab6bd8b1ae02cf6ecc1d0520b76c68cdc7c12094338f04c19e2df5d7ae30d681e858871c4f1963ae39e4969ed61139959cf4b300030fc
168+
checksum: ebf3c8f4567cef9b4099d740f145eea6dc8335059ebfbda18d9c65701b810c46634aeeea721a6c7ebbef6cf8d11ccf1402891fee89ca90652f723987ee5c410c
169169
languageName: node
170170
linkType: hard
171171

@@ -187,16 +187,16 @@ __metadata:
187187
languageName: node
188188
linkType: hard
189189

190-
"@commitlint/read@npm:^19.2.1":
191-
version: 19.2.1
192-
resolution: "@commitlint/read@npm:19.2.1"
190+
"@commitlint/read@npm:^19.4.0":
191+
version: 19.4.0
192+
resolution: "@commitlint/read@npm:19.4.0"
193193
dependencies:
194194
"@commitlint/top-level": ^19.0.0
195195
"@commitlint/types": ^19.0.3
196196
execa: ^8.0.1
197197
git-raw-commits: ^4.0.0
198198
minimist: ^1.2.8
199-
checksum: 840ebd183b2fe36dea03701552d825a9a1770d300b9416ab2a731fdeed66cf8c9dd8be133d92ac017cb9bf29e2ef5aee91a641f2b643bb5b33005f7b392ec953
199+
checksum: 732ab482c3acc7cf00d28db02d45701f38c381712a46e2d5f5f7faabc14b87d849c64184df80b7d197083a71fbd7ec05cc5ae6a1814c1590543f9489e46f9d28
200200
languageName: node
201201
linkType: hard
202202

@@ -776,7 +776,7 @@ __metadata:
776776
version: 0.0.0-use.local
777777
resolution: "@openapi-typescript-infra/service@workspace:."
778778
dependencies:
779-
"@commitlint/cli": ^19.3.0
779+
"@commitlint/cli": ^19.4.0
780780
"@commitlint/config-conventional": ^19.2.2
781781
"@godaddy/terminus": ^4.12.1
782782
"@openapi-typescript-infra/coconfig": ^4.4.0

0 commit comments

Comments
 (0)