Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09703a1

Browse files
authored
Addrequest_id toClient log lines (#618)
## DescriptionThis PR parses `request_id` from the response of Notion API requests in`errors.ts` and includes them in the logger log lines in `Client.ts`.The idea is to encourage providing these in issue reports to Notion, sosupport teams can more easily debug issues.## How was this change tested?- [ ] Automated test (unit, integration, etc.)- [x] Manual test (provide reproducible testing steps below)Manually tested a failing request and a succeeding request and confirmedthe `request_id` is included in the log lines for both.## Screenshots```ts@notionhq/client warn: request fail { code: 'unauthorized', message: 'API token is invalid.', requestId: '83843712-fa08-452b-9282-0c9dcbdcb51f'}``````tsQuerying database...@notionhq/client info: request start { method: 'post', path: 'data_sources/bb1734fe-3d6c-44e1-8984-9525023c482f/query'}@notionhq/client info: request success { method: 'post', path: 'data_sources/bb1734fe-3d6c-44e1-8984-9525023c482f/query', requestId: '895abceb-15a0-47e0-91d3-84c26dfd3749'}```
1 parentc1fc444 commit09703a1

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

‎src/Client.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export default class Client {
178178
/**
179179
* Sends a request.
180180
*/
181-
publicasyncrequest<ResponseBody>(
181+
publicasyncrequest<ResponseBodyextendsobject>(
182182
args:RequestParameters
183183
):Promise<ResponseBody>{
184184
const{ path, method, query, body, formDataParams, auth}=args
@@ -272,7 +272,13 @@ export default class Client {
272272
}
273273

274274
constresponseJson:ResponseBody=JSON.parse(responseText)
275-
this.log(LogLevel.INFO,"request success",{ method, path})
275+
this.log(LogLevel.INFO,"request success",{
276+
method,
277+
path,
278+
...("request_id"inresponseJson&&responseJson.request_id
279+
?{requestId:responseJson.request_id}
280+
:{}),
281+
})
276282
returnresponseJson
277283
}catch(error:unknown){
278284
if(!isNotionClientError(error)){
@@ -283,6 +289,9 @@ export default class Client {
283289
this.log(LogLevel.WARN,"request fail",{
284290
code:error.code,
285291
message:error.message,
292+
...("request_id"inerror&&error.request_id
293+
?{requestId:error.request_id}
294+
:{}),
286295
})
287296

288297
if(isHTTPResponseError(error)){

‎src/errors.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class HTTPResponseError<
130130
readonlyheaders:SupportedResponse["headers"]
131131
readonlybody:string
132132
readonlyadditional_data:AdditionalData|undefined
133+
readonlyrequest_id:string|undefined
133134

134135
constructor(args:{
135136
code:Code
@@ -138,14 +139,17 @@ class HTTPResponseError<
138139
headers:SupportedResponse["headers"]
139140
rawBodyText:string
140141
additional_data:AdditionalData|undefined
142+
request_id:string|undefined
141143
}){
142144
super(args.message)
143-
const{ code, status, headers, rawBodyText, additional_data}=args
145+
const{ code, status, headers, rawBodyText, additional_data, request_id}=
146+
args
144147
this.code=code
145148
this.status=status
146149
this.headers=headers
147150
this.body=rawBodyText
148151
this.additional_data=additional_data
152+
this.request_id=request_id
149153
}
150154
}
151155

@@ -199,6 +203,7 @@ export class UnknownHTTPResponseError extends HTTPResponseError<ClientErrorCode.
199203
args.message??
200204
`Request to Notion API failed with status:${args.status}`,
201205
additional_data:undefined,
206+
request_id:undefined,
202207
})
203208
}
204209

@@ -231,6 +236,7 @@ const apiErrorCodes: { [C in APIErrorCode]: true } = {
231236
*/
232237
exportclassAPIResponseErrorextendsHTTPResponseError<APIErrorCode>{
233238
readonlyname="APIResponseError"
239+
readonlyrequest_id:string|undefined
234240

235241
staticisAPIResponseError(error:unknown):error isAPIResponseError{
236242
returnisNotionClientErrorWithCode(error,apiErrorCodes)
@@ -250,6 +256,7 @@ export function buildRequestError(
250256
status:response.status,
251257
rawBodyText:bodyText,
252258
additional_data:apiErrorResponseBody.additional_data,
259+
request_id:apiErrorResponseBody.request_id,
253260
})
254261
}
255262
returnnewUnknownHTTPResponseError({
@@ -265,6 +272,7 @@ function parseAPIErrorResponseBody(body: string):
265272
code:APIErrorCode
266273
message:string
267274
additional_data:AdditionalData|undefined
275+
request_id:string|undefined
268276
}
269277
|undefined{
270278
if(typeofbody!=="string"){
@@ -286,11 +294,17 @@ function parseAPIErrorResponseBody(body: string):
286294
return
287295
}
288296

297+
constadditional_data=parsed["additional_data"]as
298+
|AdditionalData
299+
|undefined
300+
constrequest_id=parsed["request_id"]asstring|undefined
301+
289302
return{
290303
...parsed,
291304
code:parsed["code"],
292305
message:parsed["message"],
293-
additional_data:parsed["additional_data"]asAdditionalData|undefined,
306+
additional_data,
307+
request_id,
294308
}
295309
}
296310

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp