Skip to content

Commit

Permalink
fix: correctly test error is retriable
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesRudolph committed Feb 9, 2022
1 parent 9b5f03b commit 28677fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.7.0",
"version": "0.8.0",
"name": "@meshcloud/notion-markdown-cms",
"engines": {
"node": ">=14"
Expand Down
15 changes: 8 additions & 7 deletions src/NotionApiFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class NotionApiFacade {
}

async retrieveDatabase(databaseId: string) {
return await this.withRetry(async () =>
this.client.databases.retrieve({
return await this.withRetry(async () => {
return this.client.databases.retrieve({
database_id: databaseId,
})
);
});
});
}

async queryDatabase(query: DatabasesQueryParameters) {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class NotionApiFacade {
APIErrorCode.RateLimited,
],
retriableUnknownHTTPStatusCodes: number[] = [502]
) {
): Promise<T> {
let lastError: any;

for (let i = 1; i <= maxRetries; i++) {
Expand All @@ -99,8 +99,9 @@ export class NotionApiFacade {
RequestTimeoutError.isRequestTimeoutError(error) && error;

const isRetriable =
(apiError && error.code in retriableApiErrorCodes) ||
(unknownError && error.status in retriableUnknownHTTPStatusCodes) ||
(apiError && retriableApiErrorCodes.includes(error.code)) ||
(unknownError &&
retriableUnknownHTTPStatusCodes.includes(error.status)) ||
timeoutError;

if (!isRetriable) {
Expand Down

0 comments on commit 28677fc

Please sign in to comment.