Skip to content

Commit 2e403c3

Browse files
author
matus.hudec
committed
comments
1 parent 38f3ede commit 2e403c3

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/httpClient/redisStorage.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ import type { StorageValue } from 'axios-cache-interceptor';
33
// eslint-disable-next-line import/no-extraneous-dependencies
44
import { createClient } from 'redis';
55

6+
const keyPrefix = 'axios-cache-';
7+
68
export default function createRedisStorage(client: ReturnType<typeof createClient>) {
79
// source https://axios-cache-interceptor.js.org/guide/storages#node-redis-storage
810
return buildStorage({
911
async find(key) {
10-
const result = await client.get(`axios-cache-${key}`);
12+
const result = await client.get(`${keyPrefix}${key}`);
1113
return result ? (JSON.parse(result) as StorageValue) : undefined;
1214
},
1315

1416
// eslint-disable-next-line complexity
1517
async set(key, value, req) {
16-
await client.set(`axios-cache-${key}`, JSON.stringify(value), {
18+
await client.set(`${keyPrefix}${key}`, JSON.stringify(value), {
1719
PXAT:
1820
value.state === 'loading'
1921
? Date.now() + (req?.cache && typeof req.cache.ttl === 'number' ? req.cache.ttl : 60000)
@@ -25,7 +27,7 @@ export default function createRedisStorage(client: ReturnType<typeof createClien
2527
},
2628

2729
async remove(key) {
28-
await client.del(`axios-cache-${key}`);
30+
await client.del(`${keyPrefix}${key}`);
2931
},
3032
});
3133
}

src/logger/logger.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import stringify from 'fast-safe-stringify';
55
import isError from 'is-error';
66
import { redactSecret } from '../util';
77

8+
const defaultPayloadLimit = 32768;
9+
10+
const minPayloadLimit = 10000;
11+
812
export default class Logger {
913
public invocationId: string;
1014

@@ -19,10 +23,11 @@ export default class Logger {
1923
constructor(configuration?: LoggerConfiguration) {
2024
this.logFunction = configuration?.logFunction ?? console.log;
2125
this.jsonSpace = configuration?.jsonSpace ?? 2;
22-
this.payloadLimit =
23-
!configuration?.payloadLimit || configuration?.payloadLimit < 10000
24-
? 32768
25-
: configuration?.payloadLimit;
26+
this.payloadLimit = !configuration?.payloadLimit
27+
? defaultPayloadLimit
28+
: configuration?.payloadLimit < minPayloadLimit
29+
? minPayloadLimit
30+
: configuration.payloadLimit;
2631

2732
this.invocationId = 'none';
2833
}

src/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ export function serializeObject(obj: unknown, redact?: boolean): object {
3838
: JSON.parse(JSON.stringify(modObj));
3939
}
4040

41-
export function serializeAxiosError(error: AxiosError): SerializedAxiosError | undefined {
41+
export function serializeAxiosError(error: AxiosError<any>): SerializedAxiosError | undefined {
4242
if (!error.response) {
4343
return {
4444
status: 500,
4545
details: error,
4646
};
4747
}
4848

49-
const { status, data } = error.response as any;
49+
const { status, data } = error.response;
5050
return {
5151
status: data.originalStatusCode ?? status, // Propagate original status code of ClientException
5252
details: data.details && Object.keys(data.details).length > 0 ? data.details : data, // Prevent wrapping of Exception

0 commit comments

Comments
 (0)