fix(server): convert 4xx status HttpError to UserFriendlyError (#10956)

This commit is contained in:
fengmk2
2025-03-18 09:28:50 +00:00
parent 5cb2abab76
commit 86c4e0705f
12 changed files with 78 additions and 6 deletions
@@ -1,6 +1,7 @@
import { type Blob } from '@prisma/client';
import { TestingApp } from './testing-app';
import { TEST_LOG_LEVEL } from './utils';
export async function listBlobs(
app: TestingApp,
@@ -73,5 +74,13 @@ export async function setBlob(
`blob-${Math.random().toString(16).substring(2, 10)}.data`
)
.expect(200);
if (res.body.errors?.length) {
if (TEST_LOG_LEVEL !== 'fatal') {
// print the error stack when log level is not fatal, for better debugging
console.error('%o', res.body);
}
throw new Error(res.body.errors[0].message);
}
return res.body.data.setBlob;
}
@@ -169,3 +169,15 @@ test('should accept blob even storage out of quota if workspace has unlimited fe
await t.notThrowsAsync(setBlob(app, workspace.id, buffer));
await t.notThrowsAsync(setBlob(app, workspace.id, buffer));
});
test('should throw error when blob size large than max file size', async t => {
await app.signup();
const workspace = await createWorkspace(app);
const buffer = Buffer.from(new Uint8Array(1024 * 1024 * 11));
await t.throwsAsync(setBlob(app, workspace.id, buffer), {
message:
'HTTP request error, message: File truncated as it exceeds the 10485760 byte size limit.',
});
});