Skip to content

Commit 4f6ddc9

Browse files
committed
Change AbstractApolloErrorProcessor to concrete ApolloErrorProcessor
1 parent 36ddad8 commit 4f6ddc9

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function isGraphQLError(error: GraphQLError | any): error is GraphQLError
1818
return error.extensions !== undefined;
1919
}
2020

21-
export abstract class AbstractApolloErrorProcessor<TApp = Vue, TContext = ApolloOperationContext> {
21+
export class ApolloErrorProcessor<TApp = Vue, TContext = ApolloOperationContext> {
2222
public static FriendlyMessages: Record<string, string> = {
2323
FAILED_TO_FETCH:
2424
'Unable to communicate with server. The service may be down or you may be offline. Try again in a moment.',
@@ -39,7 +39,13 @@ export abstract class AbstractApolloErrorProcessor<TApp = Vue, TContext = Apollo
3939
this.processedErrors = this.processApolloError(error);
4040
}
4141

42-
public abstract showErrorNotifications(): void;
42+
public showErrorNotifications(): void {
43+
// This is just an example - to do something else (e.g. showing a visible notification to the user), you should
44+
// implement your own class that extends ApolloErrorProcessor and replace this showErrorNotifications method.
45+
this.processedErrors.forEach(error => {
46+
console.error(`${error.type}: ${error.message}`, error.error);
47+
});
48+
}
4349

4450
public cleanError(error: ApolloError | GraphQLError | Record<string, any>): Error {
4551
if (error instanceof Error) {
@@ -93,7 +99,7 @@ export abstract class AbstractApolloErrorProcessor<TApp = Vue, TContext = Apollo
9399
protected getFriendlyMessage(errorCode: string, errorMessage: string): string;
94100
protected getFriendlyMessage(errorCode: string): string | undefined;
95101
protected getFriendlyMessage(errorCode: string, errorMessage?: string): string | undefined {
96-
return (this.constructor as typeof AbstractApolloErrorProcessor).FriendlyMessages[errorCode] ?? errorMessage;
102+
return (this.constructor as typeof ApolloErrorProcessor).FriendlyMessages[errorCode] ?? errorMessage;
97103
}
98104

99105
private processApolloError(error: ApolloError): ProcessedApolloError[] {

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file Automatically generated by barrelsby.
33
*/
44

5-
export * from './AbstractApolloErrorProcessor';
5+
export * from './ApolloErrorProcessor';
66
export * from './mutation';
77
export * from './query';
88
export * from './subscription';

0 commit comments

Comments
 (0)