nakedobjects.spa
Version:
Single Page Application client for a Naked Objects application.
84 lines • 3.87 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { UrlManagerService } from './url-manager.service';
import { ContextService } from './context.service';
import * as Models from './models';
import { Injectable } from '@angular/core';
import { ConfigService } from './config.service';
var ErrorService = (function () {
function ErrorService(urlManager, context, configService) {
var _this = this;
this.urlManager = urlManager;
this.context = context;
this.configService = configService;
this.preProcessors = [];
this.setErrorPreprocessor(function (reject) {
if (reject.category === Models.ErrorCategory.HttpClientError && reject.httpErrorCode === Models.HttpStatusCode.PreconditionFailed) {
if (reject.originalUrl) {
var oid = Models.ObjectIdWrapper.fromHref(reject.originalUrl, configService.config.keySeparator);
_this.context.setConcurrencyError(oid);
reject.handled = true;
}
}
});
}
ErrorService.prototype.handleHttpServerError = function (reject) {
this.urlManager.setError(Models.ErrorCategory.HttpServerError);
};
ErrorService.prototype.handleHttpClientError = function (reject, displayMessages) {
switch (reject.httpErrorCode) {
case (Models.HttpStatusCode.UnprocessableEntity):
displayMessages(reject.error);
break;
default:
this.urlManager.setError(Models.ErrorCategory.HttpClientError, reject.httpErrorCode);
}
};
ErrorService.prototype.handleClientError = function (reject) {
this.urlManager.setError(Models.ErrorCategory.ClientError, reject.clientErrorCode);
};
ErrorService.prototype.handleError = function (reject) {
this.handleErrorAndDisplayMessages(reject, function () { });
};
;
ErrorService.prototype.handleErrorAndDisplayMessages = function (reject, displayMessages) {
this.preProcessors.forEach(function (p) { return p(reject); });
if (reject.handled) {
return;
}
reject.handled = true;
this.context.setError(reject);
switch (reject.category) {
case (Models.ErrorCategory.HttpServerError):
this.handleHttpServerError(reject);
break;
case (Models.ErrorCategory.HttpClientError):
this.handleHttpClientError(reject, displayMessages);
break;
case (Models.ErrorCategory.ClientError):
this.handleClientError(reject);
break;
}
};
;
ErrorService.prototype.setErrorPreprocessor = function (handler) {
this.preProcessors.push(handler);
};
;
return ErrorService;
}());
ErrorService = __decorate([
Injectable(),
__metadata("design:paramtypes", [UrlManagerService,
ContextService,
ConfigService])
], ErrorService);
export { ErrorService };
//# sourceMappingURL=error.service.js.map