From 9bb838afbb3fe9c13810777c8811dacedd19e093 Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Wed, 17 May 2017 12:40:21 -0700 Subject: [PATCH 1/2] Show toast on data source error Fixes #83 --- src/data-sources/plugins/DataSourcePlugin.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/data-sources/plugins/DataSourcePlugin.ts b/src/data-sources/plugins/DataSourcePlugin.ts index c6d15f8f..a29bf248 100644 --- a/src/data-sources/plugins/DataSourcePlugin.ts +++ b/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 */ @@ -116,6 +118,21 @@ export abstract class DataSourcePlugin implements IDataSourcePlugin { } failure(error: any): void { + ToastActions.addToast({ text: this.errorToMessage(error) }); return error; } + + private errorToMessage(error: any): string { + const exception = error as Error; + if (exception == null) { + return error; + } + + const message = exception.message; + if (message === '[object ProgressEvent]') { + return 'There is a problem connecting to the internet.'; + } + + return `Error: ${message}`; + } } \ No newline at end of file From 5961bc7d5aed813b4f2b3ecfae3de0fe797e8adf Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Thu, 18 May 2017 08:54:14 -0700 Subject: [PATCH 2/2] Fix incorrect use of as operator --- src/data-sources/plugins/DataSourcePlugin.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/data-sources/plugins/DataSourcePlugin.ts b/src/data-sources/plugins/DataSourcePlugin.ts index a29bf248..1eb2fec1 100644 --- a/src/data-sources/plugins/DataSourcePlugin.ts +++ b/src/data-sources/plugins/DataSourcePlugin.ts @@ -123,12 +123,11 @@ export abstract class DataSourcePlugin implements IDataSourcePlugin { } private errorToMessage(error: any): string { - const exception = error as Error; - if (exception == null) { + if (!(error instanceof Error)) { return error; } - const message = exception.message; + const message = (error as Error).message; if (message === '[object ProgressEvent]') { return 'There is a problem connecting to the internet.'; }