Hacky fix for message loop

Needs to be properly fixed later
This commit is contained in:
Rohan Sircar 2020-05-29 13:06:09 +05:30
parent daf1f8d253
commit 388d339c28
2 changed files with 33 additions and 30 deletions

View File

@ -211,10 +211,6 @@ export class ChatModelHelper {
lastMessageTimeStamp: Date lastMessageTimeStamp: Date
): Promise<any> { ): Promise<any> {
const headers = new Headers(); const headers = new Headers();
if (JsonAPI.authToken == null) {
log.error("authToken null");
return;
}
headers.append("X-AUTH-TOKEN", JsonAPI.authToken); headers.append("X-AUTH-TOKEN", JsonAPI.authToken);
// const url = Sprintf(JsonAPI.CHAT_MESSAGES_GET, toUser, page, 5); // const url = Sprintf(JsonAPI.CHAT_MESSAGES_GET, toUser, page, 5);
// log.debug(url) // log.debug(url)
@ -228,9 +224,7 @@ export class ChatModelHelper {
} }
); );
log.debug(response.clone()); log.debug(response.clone());
if (fetchErrorHandler(response.clone(), this._notificationService)) { if(!response.ok) location.reload();
return null;
}
const data: Promise<any> = await response.json(); const data: Promise<any> = await response.json();
function func(data: any) { function func(data: any) {
const d1 = data.map((d: any) => { const d1 = data.map((d: any) => {

View File

@ -7,26 +7,35 @@ import { Sprintf } from "../singleton/Sprintf";
// import sprintf = require('sprintf-js').sprintf; // import sprintf = require('sprintf-js').sprintf;
export function fetchErrorHandler(response: Response, ns: NotificationService) { export function fetchErrorHandler(response: Response, ns: NotificationService) {
// alertify.success('Current position : ' + alertify.get('notifier', 'position')); // alertify.success('Current position : ' + alertify.get('notifier', 'position'));
if (!response.ok) { if (!response.ok) {
return response.text().catch(err => { return response
// the status was not ok and there is no json body .text()
// throw new Error(response.statusText); .catch((err) => {
// window.alert(sprintf('Some error occured. Http code is %s', response.status)); // the status was not ok and there is no json body
ns.error(Sprintf('Some error occured. Http code is %s', response.status)); // throw new Error(response.statusText);
// @ts-ignore // window.alert(sprintf('Some error occured. Http code is %s', response.status));
log.error(sprintf('Some error occured. Http code is %s', response.status)); ns.error(
log.error(); Sprintf("Some error occured. Http code is %s", response.status)
return true; );
}).then(json => { log.error(
// the status was not ok but there is a json body Sprintf("Some error occured. Http code is %s", response.status)
// 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)); log.error();
ns.error(Sprintf('Some error occured. Http code is %s', response.status)); return true;
// @ts-ignore })
log.error(sprintf('Some error occured. Http code is %s', response.status)); .then((json) => {
log.error(json); // the status was not ok but there is a json body
return true; // 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;
});
}
} }