consumerportal
Version:
mydna Custimised for you
77 lines (67 loc) • 2.66 kB
text/typescript
/// <reference path="../../includes.ts" />
module errorHandlerSrvc {
import IModalService = app.IModalService;
export interface IErrorHandlerService {
errorHandler(err_obj: any, err_type: string, err_msg: string): any;
}
export class ErrorHandlerService implements IErrorHandlerService {
static $inject = [
'logSrvc',
'$rootScope',
'authenSrvc',
'modalService'
];
constructor(
private logSrvc: logSrvc.ILogService,
private $rootScope: angular.IRootScopeService,
private authenSrvc: authenSrvc.IAuthenService,
private modalService: IModalService
) {
$rootScope.$on("pop-up-call-back-emitter-root", function(event, message) {
if (message == "error-handler-srvc-ok") {
$rootScope.$emit("change-body-ng-class", { "className": "" });
$rootScope.$emit("resetTabIndexValue");
}
});
}
errorHandler(err_obj: any, err_type: string, err_msg: string) {
let message: any;
if (err_obj.status == 400) {
message = {
title: 'Error - 400 Bad Request',
content: 'A bad request was sent to the server.',
buttons: ['Close']
};
}
else if (err_obj.status == 401) {
this.authenSrvc.logOut();
}
else if (err_obj.status == 404) {
message = {
title: 'Error - 404 Not Found',
content: 'The requested information was not found.',
buttons: ['Close']
};
}
else if (err_obj.status == 500) {
message = {
title: 'Error - 500',
content: 'Server is unreachable',
buttons: ['Close']
};
}
else {
message = {
title: 'Unexpected Error ' + err_obj.status,
content: 'An expection occurred. Please give myDNA support a call',
buttons: ['Close']
};
}
if (message) {
this.modalService.add('modal-notification.warning', message);
}
this.logSrvc.logger(err_obj, err_type, err_msg);
}
}
angular.module('errorHandlerSrvc', []).service('errorHandlerSrvc', ErrorHandlerService);
}