Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 16ca4b711b | |||
| e4a814126b | |||
| 4f6ddc91ba | |||
| 36ddad8c67 | |||
| 301e22b24e |
Generated
+4
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue-apollo-smart-ops",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -9728,9 +9728,9 @@
|
||||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz",
|
||||
"integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==",
|
||||
"version": "4.2.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.4.tgz",
|
||||
"integrity": "sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==",
|
||||
"dev": true
|
||||
},
|
||||
"unbox-primitive": {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue-apollo-smart-ops",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"description": "Create TypeScript-typed operation functions for your Vue Apollo queries and mutations.",
|
||||
"author": "Madscience Ltd",
|
||||
"license": "MIT",
|
||||
@@ -65,7 +65,7 @@
|
||||
"prettier": "2.2.1",
|
||||
"rimraf": "3.0.2",
|
||||
"ts-jest": "26.5.4",
|
||||
"typescript": "4.2.3",
|
||||
"typescript": "4.2.4",
|
||||
"vue": "2.6.12",
|
||||
"vue-apollo": "3.0.7",
|
||||
"vue-jest": "3.0.7"
|
||||
|
||||
@@ -18,7 +18,7 @@ export function isGraphQLError(error: GraphQLError | any): error is GraphQLError
|
||||
return error.extensions !== undefined;
|
||||
}
|
||||
|
||||
export abstract class AbstractApolloErrorProcessor<TApp = Vue, TContext = ApolloOperationContext> {
|
||||
export class ApolloErrorProcessor<TApp = Vue, TContext = ApolloOperationContext> {
|
||||
public static FriendlyMessages: Record<string, string> = {
|
||||
FAILED_TO_FETCH:
|
||||
'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
|
||||
this.processedErrors = this.processApolloError(error);
|
||||
}
|
||||
|
||||
public abstract showErrorNotifications(): void;
|
||||
public showErrorNotifications(): void {
|
||||
// This is just an example - to do something else (e.g. showing a visible notification to the user), you should
|
||||
// implement your own class that extends ApolloErrorProcessor and replace this showErrorNotifications method.
|
||||
this.processedErrors.forEach(error => {
|
||||
console.error(`${error.type}: ${error.message}`, error.error);
|
||||
});
|
||||
}
|
||||
|
||||
public cleanError(error: ApolloError | GraphQLError | Record<string, any>): Error {
|
||||
if (error instanceof Error) {
|
||||
@@ -93,7 +99,7 @@ export abstract class AbstractApolloErrorProcessor<TApp = Vue, TContext = Apollo
|
||||
protected getFriendlyMessage(errorCode: string, errorMessage: string): string;
|
||||
protected getFriendlyMessage(errorCode: string): string | undefined;
|
||||
protected getFriendlyMessage(errorCode: string, errorMessage?: string): string | undefined {
|
||||
return (this.constructor as typeof AbstractApolloErrorProcessor).FriendlyMessages[errorCode] ?? errorMessage;
|
||||
return (this.constructor as typeof ApolloErrorProcessor).FriendlyMessages[errorCode] ?? errorMessage;
|
||||
}
|
||||
|
||||
private processApolloError(error: ApolloError): ProcessedApolloError[] {
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ApolloErrorProcessor } from './ApolloErrorProcessor';
|
||||
import {
|
||||
ApolloError,
|
||||
ApolloErrorHandlerResult,
|
||||
ApolloOperationContext,
|
||||
ApolloOperationErrorHandlerFunction,
|
||||
} from './types';
|
||||
import { Vue } from 'vue/types/vue';
|
||||
|
||||
/**
|
||||
* This is a simple example of an error handler function. You can copy this and implement your own in your application.
|
||||
*/
|
||||
export const handleApolloError: ApolloOperationErrorHandlerFunction<ApolloError, Vue> = (
|
||||
error: ApolloError,
|
||||
app: Vue,
|
||||
context?: ApolloOperationContext,
|
||||
): ApolloErrorHandlerResult => {
|
||||
const processor = new ApolloErrorProcessor(error, app, context ?? {});
|
||||
|
||||
processor.showErrorNotifications();
|
||||
|
||||
return {
|
||||
processedErrors: processor.processedErrors,
|
||||
};
|
||||
};
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
* @file Automatically generated by barrelsby.
|
||||
*/
|
||||
|
||||
export * from './AbstractApolloErrorProcessor';
|
||||
export * from './ApolloErrorProcessor';
|
||||
export * from './mutation';
|
||||
export * from './query';
|
||||
export * from './subscription';
|
||||
|
||||
Reference in New Issue
Block a user