Skip to content

Commit 459a038

Browse files
committed
fix(aProblem): do not cache by default
BREAKING CHANGE: this changes the behaviour of aProblem
1 parent 0b74e06 commit 459a038

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/aProblem.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ void describe('aProblem()', () => {
1414
statusCode: 409,
1515
headers: {
1616
'content-type': 'application/problem+json',
17-
'Cache-Control': 'public, max-age=60',
17+
// 'Cache-Control': 'public, max-age=60',
18+
'Cache-Control': 'no-store',
1819
},
1920
body: JSON.stringify({
2021
'@context': Context.problemDetail.toString(),
@@ -23,4 +24,20 @@ void describe('aProblem()', () => {
2324
}),
2425
},
2526
))
27+
28+
void it('can set cache control', () =>
29+
assert.partialDeepStrictEqual(
30+
aProblem(
31+
{
32+
title: `A Conflict!`,
33+
status: 409,
34+
},
35+
60,
36+
),
37+
{
38+
headers: {
39+
'Cache-Control': 'public, max-age=60',
40+
},
41+
},
42+
))
2643
})

src/aProblem.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import type { APIGatewayProxyStructuredResultV2 } from 'aws-lambda'
44

55
export const aProblem = (
66
problem: Omit<Static<typeof ProblemDetail>, '@context'>,
7-
cacheForSeconds: number = 60,
7+
cacheForSeconds: number = 0,
88
): APIGatewayProxyStructuredResultV2 => ({
99
statusCode: problem.status,
1010
headers: {
1111
'content-type': 'application/problem+json',
12-
'Cache-Control': `public, max-age=${cacheForSeconds}`,
12+
'Cache-Control':
13+
cacheForSeconds > 0 ? `public, max-age=${cacheForSeconds}` : 'no-store',
1314
},
1415
body: JSON.stringify({
1516
'@context': Context.problemDetail.toString(),

0 commit comments

Comments
 (0)