From 4c5eae5b2dd2e51ffa8f92bef6f7a2b895a31792 Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Tue, 2 Aug 2016 13:13:44 +0200 Subject: [PATCH] Fix error resource handling --- .../work-package-resource.service.ts | 2 +- .../work-package-comment.directive.ts | 9 ++++---- .../wp-display-attr.directive.ts | 4 +--- .../wp-edit/wp-edit-form.directive.ts | 5 ++--- .../wp-edit/wp-notification.service.ts | 3 +-- .../wp-parent-relation-group.service.ts | 21 +++++++------------ 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts index bfc7eb3155..716c0d7365 100644 --- a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts +++ b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts @@ -201,7 +201,7 @@ export class WorkPackageResource extends HalResource { public getForm() { if (!this.form) { this.updateForm(this.$source).catch(error => { - NotificationsService.addError(error.data.message); + NotificationsService.addError(error.message); }); } diff --git a/frontend/app/components/work-packages/work-package-comment/work-package-comment.directive.ts b/frontend/app/components/work-packages/work-package-comment/work-package-comment.directive.ts index cf115ae9e3..17cca6ebb3 100644 --- a/frontend/app/components/work-packages/work-package-comment/work-package-comment.directive.ts +++ b/frontend/app/components/work-packages/work-package-comment/work-package-comment.directive.ts @@ -32,8 +32,8 @@ import {WorkPackageCommentField} from './wp-comment-field.module'; import {ErrorResource} from '../../api/api-v3/hal-resources/error-resource.service'; import {WorkPackageNotificationService} from '../../wp-edit/wp-notification.service'; import {WorkPackageCacheService} from '../work-package-cache.service'; -export class CommentFieldDirectiveController { +export class CommentFieldDirectiveController { public workPackage:WorkPackageResourceInterface; public field:WorkPackageCommentField; public loadingPromise:ng.IPromise; @@ -112,9 +112,10 @@ export class CommentFieldDirectiveController { }); }) .catch(error => { - if (error.data instanceof ErrorResource) { - this.wpNotificationsService.showError(error.data, this.workPackage); - } else { + if (error instanceof ErrorResource) { + this.wpNotificationsService.showError(error, this.workPackage); + } + else { this.NotificationsService.addError(this.I18n.t('js.work_packages.comment_send_failed')); } }) diff --git a/frontend/app/components/work-packages/wp-display-attr/wp-display-attr.directive.ts b/frontend/app/components/work-packages/wp-display-attr/wp-display-attr.directive.ts index becbea29a8..e1e30ca228 100644 --- a/frontend/app/components/work-packages/wp-display-attr/wp-display-attr.directive.ts +++ b/frontend/app/components/work-packages/wp-display-attr/wp-display-attr.directive.ts @@ -89,9 +89,7 @@ export class WorkPackageDisplayAttributeController { if (this.isEmpty) { return this.placeholder; } - else { - return this.field.valueString; - } + return this.field.valueString; } protected updateAttribute(wp) { diff --git a/frontend/app/components/wp-edit/wp-edit-form.directive.ts b/frontend/app/components/wp-edit/wp-edit-form.directive.ts index f5750b8ca4..1d3a045556 100644 --- a/frontend/app/components/wp-edit/wp-edit-form.directive.ts +++ b/frontend/app/components/wp-edit/wp-edit-form.directive.ts @@ -134,8 +134,8 @@ export class WorkPackageEditFormController { }) .catch((error) => { this.wpNotificationsService.handleErrorResponse(error, this.workPackage); - if (error.data instanceof ErrorResource) { - this.handleSubmissionErrors(error.data, deferred); + if (error instanceof ErrorResource) { + this.handleSubmissionErrors(error, deferred); } }); @@ -143,7 +143,6 @@ export class WorkPackageEditFormController { } private handleSubmissionErrors(error:any, deferred:any) { - // Process single API errors this.handleErroneousAttributes(error); return deferred.reject(); diff --git a/frontend/app/components/wp-edit/wp-notification.service.ts b/frontend/app/components/wp-edit/wp-notification.service.ts index 744073d913..ea2718c268 100644 --- a/frontend/app/components/wp-edit/wp-notification.service.ts +++ b/frontend/app/components/wp-edit/wp-notification.service.ts @@ -53,8 +53,7 @@ export class WorkPackageNotificationService { this.NotificationsService.addSuccess(message); } - public handleErrorResponse(error, workPackage?:WorkPackageResource) { - const errorResource = error.data; + public handleErrorResponse(errorResource, workPackage?:WorkPackageResource) { if (!(errorResource instanceof ErrorResource)) { return this.showGeneralError(); } diff --git a/frontend/app/components/wp-relations/wp-relation-group/wp-parent-relation-group.service.ts b/frontend/app/components/wp-relations/wp-relation-group/wp-parent-relation-group.service.ts index d1e933a9db..e09c0e9803 100644 --- a/frontend/app/components/wp-relations/wp-relation-group/wp-parent-relation-group.service.ts +++ b/frontend/app/components/wp-relations/wp-relation-group/wp-parent-relation-group.service.ts @@ -28,20 +28,15 @@ import {WorkPackageRelationGroup} from './wp-relation-group.service'; import {wpTabsModule} from '../../../angular-modules'; -import {WorkPackageCacheService} from "../../work-packages/work-package-cache.service"; -import { - WorkPackageResource, - WorkPackageResourceInterface -} from "../../api/api-v3/hal-resources/work-package-resource.service"; -import {WorkPackageNotificationService} from "../../wp-edit/wp-notification.service"; -import {ErrorResource} from "../../api/api-v3/hal-resources/error-resource.service"; +import {WorkPackageCacheService} from '../../work-packages/work-package-cache.service'; +import {WorkPackageNotificationService} from '../../wp-edit/wp-notification.service'; +import {ErrorResource} from '../../api/api-v3/hal-resources/error-resource.service'; var $q:ng.IQService; var HalResource; var PathHelper:any; var wpCacheService:WorkPackageCacheService; var wpNotificationsService:WorkPackageNotificationService; -var $q:ng.IQService; export class WorkPackageParentRelationGroup extends WorkPackageRelationGroup { public get canAddRelation():boolean { @@ -85,9 +80,10 @@ export class WorkPackageParentRelationGroup extends WorkPackageRelationGroup { return wpCacheService.updateWorkPackage(wp); }) .catch(error => { - if (error.data instanceof ErrorResource) { - wpNotificationsService.showError(error.data, this.workPackage); - } else { + if (error instanceof ErrorResource) { + wpNotificationsService.showError(error, this.workPackage); + } + else { wpNotificationsService.showGeneralError(); } }); @@ -95,8 +91,7 @@ export class WorkPackageParentRelationGroup extends WorkPackageRelationGroup { protected init() { if (this.workPackage.parent) { - this.workPackage.parent.$load() - .then(parent => this.relations.push(parent)); + this.workPackage.parent.$load().then(parent => this.relations.push(parent)); } } }