Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #132 from c-w/bugfix-83
Browse files Browse the repository at this point in the history
Show toast on data source error
  • Loading branch information
Mor Shemesh committed May 21, 2017
2 parents 125358a + 5961bc7 commit 29ec245
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/data-sources/plugins/DataSourcePlugin.ts
@@ -1,4 +1,6 @@

import { ToastActions } from '../../components/Toast';

export interface IDataSourceOptions {
dependencies: (string | Object)[];
/** This would be variable storing the results */
Expand Down Expand Up @@ -116,6 +118,20 @@ export abstract class DataSourcePlugin<T> implements IDataSourcePlugin {
}

failure(error: any): void {
ToastActions.addToast({ text: this.errorToMessage(error) });
return error;
}

private errorToMessage(error: any): string {
if (!(error instanceof Error)) {
return error;
}

const message = (error as Error).message;
if (message === '[object ProgressEvent]') {
return 'There is a problem connecting to the internet.';
}

return `Error: ${message}`;
}
}

0 comments on commit 29ec245

Please sign in to comment.