From 388d339c28e66b08bc7a4d54d39cc529c0fd5e78 Mon Sep 17 00:00:00 2001 From: Rohan Sircar Date: Fri, 29 May 2020 13:06:09 +0530 Subject: [PATCH] Hacky fix for message loop Needs to be properly fixed later --- .../ts/src/model/ChatModelHelper.ts | 8 +-- .../ts/src/model/FetchErrorHandler.ts | 55 +++++++++++-------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/chatto/src/main/javascript/ts/src/model/ChatModelHelper.ts b/chatto/src/main/javascript/ts/src/model/ChatModelHelper.ts index ef198a5..e988b92 100644 --- a/chatto/src/main/javascript/ts/src/model/ChatModelHelper.ts +++ b/chatto/src/main/javascript/ts/src/model/ChatModelHelper.ts @@ -211,10 +211,6 @@ export class ChatModelHelper { lastMessageTimeStamp: Date ): Promise { const headers = new Headers(); - if (JsonAPI.authToken == null) { - log.error("authToken null"); - return; - } headers.append("X-AUTH-TOKEN", JsonAPI.authToken); // const url = Sprintf(JsonAPI.CHAT_MESSAGES_GET, toUser, page, 5); // log.debug(url) @@ -228,9 +224,7 @@ export class ChatModelHelper { } ); log.debug(response.clone()); - if (fetchErrorHandler(response.clone(), this._notificationService)) { - return null; - } + if(!response.ok) location.reload(); const data: Promise = await response.json(); function func(data: any) { const d1 = data.map((d: any) => { diff --git a/chatto/src/main/javascript/ts/src/model/FetchErrorHandler.ts b/chatto/src/main/javascript/ts/src/model/FetchErrorHandler.ts index ecf61af..571c5b6 100644 --- a/chatto/src/main/javascript/ts/src/model/FetchErrorHandler.ts +++ b/chatto/src/main/javascript/ts/src/model/FetchErrorHandler.ts @@ -7,26 +7,35 @@ import { Sprintf } from "../singleton/Sprintf"; // import sprintf = require('sprintf-js').sprintf; export function fetchErrorHandler(response: Response, ns: NotificationService) { - // alertify.success('Current position : ' + alertify.get('notifier', 'position')); - if (!response.ok) { - return response.text().catch(err => { - // the status was not ok and there is no json body - // throw new Error(response.statusText); - // window.alert(sprintf('Some error occured. Http code is %s', response.status)); - ns.error(Sprintf('Some error occured. Http code is %s', response.status)); - // @ts-ignore - log.error(sprintf('Some error occured. Http code is %s', response.status)); - log.error(); - return true; - }).then(json => { - // the status was not ok but there is a json body - // throw new Error(json.error.message); // example error message returned by a REST API - // window.alert(sprintf('Error: %s (Http code %s)', json, response.status)); - ns.error(Sprintf('Some error occured. Http code is %s', response.status)); - // @ts-ignore - log.error(sprintf('Some error occured. Http code is %s', response.status)); - log.error(json); - return true; - }); - } -} \ No newline at end of file + // alertify.success('Current position : ' + alertify.get('notifier', 'position')); + if (!response.ok) { + return response + .text() + .catch((err) => { + // the status was not ok and there is no json body + // throw new Error(response.statusText); + // window.alert(sprintf('Some error occured. Http code is %s', response.status)); + ns.error( + Sprintf("Some error occured. Http code is %s", response.status) + ); + log.error( + Sprintf("Some error occured. Http code is %s", response.status) + ); + log.error(); + return true; + }) + .then((json) => { + // the status was not ok but there is a json body + // throw new Error(json.error.message); // example error message returned by a REST API + // window.alert(sprintf('Error: %s (Http code %s)', json, response.status)); + ns.error( + Sprintf("Some error occured. Http code is %s", response.status) + ); + log.error( + Sprintf("Some error occured. Http code is %s", response.status) + ); + log.error(json); + return true; + }); + } +}