feat(server): introduce user friendly server errors (#7111)

This commit is contained in:
liuyi
2024-06-17 11:30:58 +08:00
committed by GitHub
parent 5307a55f8a
commit 54fc1197ad
65 changed files with 3170 additions and 924 deletions

View File

@@ -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;
};

View File

@@ -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);
}
};
}