Skip to content

Commit f580cfa

Browse files
authored
fix: Just reducing error log spam a bit (#306)
* fix: Just reducing error log spam a bit
1 parent 5a02285 commit f580cfa

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

packages/open-next/src/adapters/cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export default class S3Cache {
234234
},
235235
} as CacheHandlerValue;
236236
} else {
237-
error("Unknown cache type", cacheData);
237+
warn("Unknown cache type", cacheData);
238238
return null;
239239
}
240240
} catch (e) {
@@ -490,7 +490,7 @@ export default class S3Cache {
490490
);
491491
return result;
492492
} catch (e) {
493-
error("This error can usually be ignored : ", e);
493+
warn("This error can usually be ignored : ", e);
494494
return { Body: null, LastModified: null };
495495
}
496496
}

packages/open-next/src/adapters/logger.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,44 @@ export function warn(...args: any[]) {
1212
console.warn(...args);
1313
}
1414

15+
interface AwsSdkClientCommandErrorLog {
16+
clientName: string;
17+
commandName: string;
18+
error: Error & { Code?: string };
19+
}
20+
21+
type AwsSdkClientCommandErrorInput = Pick<
22+
AwsSdkClientCommandErrorLog,
23+
"clientName" | "commandName"
24+
> & {
25+
errorName: string;
26+
};
27+
28+
const DOWNPLAYED_ERROR_LOGS: AwsSdkClientCommandErrorInput[] = [
29+
{
30+
clientName: "S3Client",
31+
commandName: "GetObjectCommand",
32+
errorName: "NoSuchKey",
33+
},
34+
];
35+
36+
const isDownplayedErrorLog = (errorLog: AwsSdkClientCommandErrorLog) =>
37+
DOWNPLAYED_ERROR_LOGS.some(
38+
(downplayedInput) =>
39+
downplayedInput.clientName === errorLog?.clientName &&
40+
downplayedInput.commandName === errorLog?.commandName &&
41+
(downplayedInput.errorName === errorLog?.error?.name ||
42+
downplayedInput.errorName === errorLog?.error?.Code),
43+
);
44+
1545
export function error(...args: any[]) {
46+
if (
47+
args.some((arg: AwsSdkClientCommandErrorLog) => isDownplayedErrorLog(arg))
48+
) {
49+
warn(...args);
50+
return;
51+
}
52+
1653
console.error(...args);
1754
}
1855

0 commit comments

Comments
 (0)