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

@ -9,22 +9,31 @@ import { Sprintf } from "../singleton/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
.text()
.catch((err) => {
// the status was not ok and there is no json body // the status was not ok and there is no json body
// throw new Error(response.statusText); // throw new Error(response.statusText);
// window.alert(sprintf('Some error occured. Http code is %s', response.status)); // window.alert(sprintf('Some error occured. Http code is %s', response.status));
ns.error(Sprintf('Some error occured. Http code is %s', response.status)); ns.error(
// @ts-ignore Sprintf("Some error occured. Http code is %s", response.status)
log.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(); log.error();
return true; return true;
}).then(json => { })
.then((json) => {
// the status was not ok but there is a json body // 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 // 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)); // window.alert(sprintf('Error: %s (Http code %s)', json, response.status));
ns.error(Sprintf('Some error occured. Http code is %s', response.status)); ns.error(
// @ts-ignore Sprintf("Some error occured. Http code is %s", response.status)
log.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); log.error(json);
return true; return true;
}); });