-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(storage): added some cloudflare KV 413 error management
- Loading branch information
1 parent
c4dd574
commit e228e29
Showing
5 changed files
with
95 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/app-server/src/modules/storage/factories/cloudflare-kv.storage.models.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
import { looksLikeCloudflare413Error } from './cloudflare-kv.storage.models'; | ||
|
||
describe('cloudflare-kv storage models', () => { | ||
describe('looksLikeCloudflare413Error', () => { | ||
test('a cloudflare 413 error starts with "KV PUT failed: 413 Value length of", everything else is not a cloudflare 413 error', () => { | ||
expect(looksLikeCloudflare413Error({ | ||
error: new Error('KV PUT failed: 413 Value length of 41943339 exceeds limit of 26214400.'), | ||
})).to.eql(true); | ||
|
||
expect(looksLikeCloudflare413Error({ | ||
error: new Error('KV PUT failed: 429 Too many requests.'), | ||
})).to.eql(false); | ||
|
||
expect(looksLikeCloudflare413Error({ error: undefined })).to.eql(false); | ||
expect(looksLikeCloudflare413Error({ error: 'foo' })).to.eql(false); | ||
}); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/app-server/src/modules/storage/factories/cloudflare-kv.storage.models.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { isError } from 'lodash-es'; | ||
|
||
export { looksLikeCloudflare413Error }; | ||
|
||
function looksLikeCloudflare413Error({ error }: { error: unknown }) { | ||
if (isError(error)) { | ||
return error?.message?.startsWith('KV PUT failed: 413 Value length of') ?? false; | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters