mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 18:09:58 +08:00
refactor(server): dont convert graphql bad request into internal server error (#10203)
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import type { TestFn } from 'ava';
|
||||
import ava from 'ava';
|
||||
import request from 'supertest';
|
||||
|
||||
import { buildAppModule } from '../../app.module';
|
||||
import { createTestingApp } from '../utils';
|
||||
import { createTestingApp, TestingApp } from '../utils';
|
||||
|
||||
const gql = '/graphql';
|
||||
|
||||
const test = ava as TestFn<{
|
||||
app: INestApplication;
|
||||
app: TestingApp;
|
||||
}>;
|
||||
|
||||
test.before('start app', async t => {
|
||||
@@ -83,3 +82,9 @@ test('should be able to call apis', async t => {
|
||||
// make sure the request id is set
|
||||
t.truthy(res.headers['x-request-id']);
|
||||
});
|
||||
|
||||
test('should not throw internal error when graphql call with invalid params', async t => {
|
||||
await t.throwsAsync(t.context.app.gql(`query { workspace("1") }`), {
|
||||
message: /Failed to execute gql: query { workspace\("1"\) \}, status: 400/,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -162,12 +162,18 @@ export class TestingApp extends ApplyType<INestApplication>() {
|
||||
if (res.status !== 200) {
|
||||
throw new Error(
|
||||
`Failed to execute gql: ${query}, status: ${res.status}, body: ${JSON.stringify(
|
||||
res.body
|
||||
res.body,
|
||||
null,
|
||||
2
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user