Browse Source

Hacky fix for message loop

Needs to be properly fixed later
master
Rohan Sircar 4 years ago
parent
commit
388d339c28
  1. 8
      chatto/src/main/javascript/ts/src/model/ChatModelHelper.ts
  2. 55
      chatto/src/main/javascript/ts/src/model/FetchErrorHandler.ts

8
chatto/src/main/javascript/ts/src/model/ChatModelHelper.ts

@ -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) => {

55
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;
});
}
}
// 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;
});
}
}
Loading…
Cancel
Save