feat(server): introduce user friendly server errors (#7111)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { UserFriendlyError } from '@affine/graphql';
|
||||
import { fromPromise, Service } from '@toeverything/infra';
|
||||
|
||||
import { BackendError, NetworkError } from '../error';
|
||||
@@ -75,9 +76,7 @@ export class FetchService extends Service {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
throw new BackendError(
|
||||
new Error(`${res.status} ${res.statusText}`, reason)
|
||||
);
|
||||
throw new BackendError(UserFriendlyError.fromAnyError(reason));
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {
|
||||
gqlFetcherFactory,
|
||||
GraphQLError,
|
||||
type GraphQLQuery,
|
||||
type QueryOptions,
|
||||
type QueryResponse,
|
||||
UserFriendlyError,
|
||||
} from '@affine/graphql';
|
||||
import { fromPromise, Service } from '@toeverything/infra';
|
||||
import type { Observable } from 'rxjs';
|
||||
@@ -39,15 +39,13 @@ export class GraphQLService extends Service {
|
||||
try {
|
||||
return await this.rawGql(options);
|
||||
} catch (err) {
|
||||
if (err instanceof Array) {
|
||||
for (const error of err) {
|
||||
if (error instanceof GraphQLError && error.extensions?.code === 403) {
|
||||
this.framework.get(AuthService).session.revalidate();
|
||||
}
|
||||
}
|
||||
throw new BackendError(new Error('Graphql Error'));
|
||||
const standardError = UserFriendlyError.fromAnyError(err);
|
||||
|
||||
if (standardError.status === 403) {
|
||||
this.framework.get(AuthService).session.revalidate();
|
||||
}
|
||||
throw err;
|
||||
|
||||
throw new BackendError(standardError);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user