5 Commits

Author SHA1 Message Date
Simon Garner 16ca4b711b 0.0.3
Test / dependencies (push) Has been cancelled
Test / lint (push) Has been cancelled
Test / build (push) Has been cancelled
Test / test (push) Has been cancelled
2021-04-11 13:09:39 +12:00
Simon Garner e4a814126b Add example handleApolloError function 2021-04-11 13:09:03 +12:00
Simon Garner 4f6ddc91ba Change AbstractApolloErrorProcessor to concrete ApolloErrorProcessor 2021-04-11 13:05:29 +12:00
Renovate Bot 36ddad8c67 Update dependency typescript to v4.2.4 2021-04-11 00:35:03 +00:00
Renovate Bot 301e22b24e Update Node.js to v14.16.1 2021-04-10 22:28:56 +00:00
6 changed files with 42 additions and 11 deletions
+1 -1
View File
@@ -1 +1 @@
14.16.0
14.16.1
+4 -4
View File
@@ -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
View File
@@ -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[] {
+25
View File
@@ -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
View File
@@ -2,7 +2,7 @@
* @file Automatically generated by barrelsby.
*/
export * from './AbstractApolloErrorProcessor';
export * from './ApolloErrorProcessor';
export * from './mutation';
export * from './query';
export * from './subscription';