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
): Promise<any> {
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<any> = await response.json();
function func(data: any) {
const d1 = data.map((d: any) => {

View File

@ -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;
});
}
// 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;
});
}
}