mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 06:18:45 +08:00
fix(server): convert error type to lower case (#10301)
This commit is contained in:
@@ -104,7 +104,7 @@ export class UserFriendlyError extends Error {
|
|||||||
|
|
||||||
static fromUserFriendlyErrorJSON(body: UserFriendlyError) {
|
static fromUserFriendlyErrorJSON(body: UserFriendlyError) {
|
||||||
return new UserFriendlyError(
|
return new UserFriendlyError(
|
||||||
body.type as UserFriendlyErrorBaseType,
|
body.type.toLowerCase() as UserFriendlyErrorBaseType,
|
||||||
body.name.toLowerCase() as keyof typeof USER_FRIENDLY_ERRORS,
|
body.name.toLowerCase() as keyof typeof USER_FRIENDLY_ERRORS,
|
||||||
body.message,
|
body.message,
|
||||||
body.data
|
body.data
|
||||||
|
|||||||
@@ -7,16 +7,17 @@ import { applyUpdate, Doc as YDoc } from 'yjs';
|
|||||||
|
|
||||||
import { createTestingApp, type TestingApp } from '../../../__tests__/utils';
|
import { createTestingApp, type TestingApp } from '../../../__tests__/utils';
|
||||||
import { AppModule } from '../../../app.module';
|
import { AppModule } from '../../../app.module';
|
||||||
import { Config, InternalServerError } from '../../../base';
|
import { Config, UserFriendlyError } from '../../../base';
|
||||||
import { ConfigModule } from '../../../base/config';
|
import { ConfigModule } from '../../../base/config';
|
||||||
import { Models } from '../../../models';
|
import { Models } from '../../../models';
|
||||||
import { DocReader } from '..';
|
import { DatabaseDocReader, DocReader } from '..';
|
||||||
import { RpcDocReader } from '../reader';
|
import { RpcDocReader } from '../reader';
|
||||||
|
|
||||||
const test = ava as TestFn<{
|
const test = ava as TestFn<{
|
||||||
models: Models;
|
models: Models;
|
||||||
app: TestingApp;
|
app: TestingApp;
|
||||||
docReader: DocReader;
|
docReader: DocReader;
|
||||||
|
databaseDocReader: DatabaseDocReader;
|
||||||
config: Config;
|
config: Config;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ test.before(async t => {
|
|||||||
|
|
||||||
t.context.models = app.get(Models);
|
t.context.models = app.get(Models);
|
||||||
t.context.docReader = app.get(DocReader);
|
t.context.docReader = app.get(DocReader);
|
||||||
|
t.context.databaseDocReader = app.get(DatabaseDocReader);
|
||||||
t.context.config = app.get(Config);
|
t.context.config = app.get(Config);
|
||||||
t.context.app = app;
|
t.context.app = app;
|
||||||
});
|
});
|
||||||
@@ -69,14 +71,18 @@ test('should return null when doc not found', async t => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should throw error when doc service internal error', async t => {
|
test('should throw error when doc service internal error', async t => {
|
||||||
const { docReader } = t.context;
|
const { docReader, databaseDocReader } = t.context;
|
||||||
const docId = randomUUID();
|
const docId = randomUUID();
|
||||||
mock.method(docReader, 'getDoc', async () => {
|
mock.method(databaseDocReader, 'getDoc', async () => {
|
||||||
throw new InternalServerError('mock doc service internal error');
|
throw new Error('mock doc service internal error');
|
||||||
});
|
});
|
||||||
await t.throwsAsync(docReader.getDoc(workspace.id, docId), {
|
const err = await t.throwsAsync(docReader.getDoc(workspace.id, docId), {
|
||||||
instanceOf: InternalServerError,
|
instanceOf: UserFriendlyError,
|
||||||
|
message: 'An internal error occurred.',
|
||||||
|
name: 'internal_server_error',
|
||||||
});
|
});
|
||||||
|
t.is(err.type, 'internal_server_error');
|
||||||
|
t.is(err.status, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should fallback to database doc reader when endpoint network error', async t => {
|
test('should fallback to database doc reader when endpoint network error', async t => {
|
||||||
|
|||||||
Reference in New Issue
Block a user