From 46a291dd462c0abc6e4d59f3d73a913191b6c138 Mon Sep 17 00:00:00 2001 From: Jj! Date: Wed, 27 Feb 2019 15:21:37 -0600 Subject: [PATCH 1/3] [#8] add cause field to ErrorResponse --- .../admin/ui/controller/ErrorResponse.java | 12 ++++++++++-- .../ui/controller/MetadataResolversController.java | 2 +- .../controller/support/RestControllersSupport.java | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/ErrorResponse.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/ErrorResponse.java index f3f84169d..c61edba43 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/ErrorResponse.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/ErrorResponse.java @@ -16,9 +16,17 @@ public class ErrorResponse { private String errorCode; private String errorMessage; + private String cause; + + public ErrorResponse(String errorCode, String errorMessage) { + this(errorCode, errorMessage, null); + } public ErrorResponse(HttpStatus httpStatus, String errorMessage) { - this.errorCode = String.valueOf(httpStatus.value()); - this.errorMessage = errorMessage; + this(httpStatus, errorMessage, null); + } + + public ErrorResponse(HttpStatus httpStatus, String errorCode, String cause) { + this(String.valueOf(httpStatus.value()), errorCode, cause); } } diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/MetadataResolversController.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/MetadataResolversController.java index b9a7ab3f0..384cbe26c 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/MetadataResolversController.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/MetadataResolversController.java @@ -71,7 +71,7 @@ public class MetadataResolversController { @ExceptionHandler({InvalidTypeIdException.class, IOException.class, HttpMessageNotReadableException.class}) public ResponseEntity unableToParseJson(Exception ex) { - return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.toString(), ex.getMessage())); + return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.toString(), ex.getMessage(), ex.getCause().getMessage())); } @GetMapping("/MetadataResolvers") diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/support/RestControllersSupport.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/support/RestControllersSupport.java index ebaa4da08..f3fc8d2d7 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/support/RestControllersSupport.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/controller/support/RestControllersSupport.java @@ -48,7 +48,7 @@ public ResponseEntity handleDatabaseConstraintViolation(Constrain @ExceptionHandler(Exception.class) public final ResponseEntity handleAllOtherExceptions(Exception ex) { - ErrorResponse errorResponse = new ErrorResponse("400", ex.getLocalizedMessage()); + ErrorResponse errorResponse = new ErrorResponse("400", ex.getLocalizedMessage(), ex.getCause().getLocalizedMessage()); return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); } From 9c9162dfe3a1fda5da1a4fed712524a7511089a9 Mon Sep 17 00:00:00 2001 From: Jj! Date: Wed, 27 Feb 2019 15:30:12 -0600 Subject: [PATCH 2/3] [#8] update test for new field --- .../admin/ui/controller/EntityDescriptorControllerTests.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy index cf9c736d3..928cd18ec 100644 --- a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy +++ b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy @@ -815,7 +815,7 @@ class EntityDescriptorControllerTests extends Specification { then: result.andExpect(status().isConflict()) - .andExpect(content().string("{\"errorCode\":\"409\",\"errorMessage\":\"The entity descriptor with entity id [http://test.scaldingspoon.org/test1] already exists.\"}")) + .andExpect(content().string("{\"errorCode\":\"409\",\"errorMessage\":\"The entity descriptor with entity id [http://test.scaldingspoon.org/test1] already exists.\",\"cause\":null}")) } @Ignore("until we handle the workaround for SHIBUI-1237") From b4357e8e3e84b33880230b7c7311e37e952bf840 Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Wed, 27 Feb 2019 15:04:37 -0700 Subject: [PATCH 3/3] added message handling in error --- .../provider/effect/collection.effect.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ui/src/app/metadata/provider/effect/collection.effect.ts b/ui/src/app/metadata/provider/effect/collection.effect.ts index c0a421188..2a521a501 100644 --- a/ui/src/app/metadata/provider/effect/collection.effect.ts +++ b/ui/src/app/metadata/provider/effect/collection.effect.ts @@ -101,7 +101,9 @@ export class CollectionEffects { .save(provider) .pipe( map(p => new AddProviderSuccess(p)), - catchError((e) => of(new AddProviderFail(e.error))) + catchError((e) => { + return of(new AddProviderFail(e.error)); + }) ) ) ); @@ -111,13 +113,17 @@ export class CollectionEffects { ofType(ProviderCollectionActionTypes.ADD_PROVIDER_FAIL), map(action => action.payload), withLatestFrom(this.store.select(fromI18n.getMessages)), - map(([error, messages]) => new AddNotification( - new Notification( - NotificationType.Danger, - `${error.errorCode}: ${ this.i18nService.translate(error.errorMessage, null, messages) }`, - 8000 - ) - )) + map(([error, messages]) => { + let message = `${error.errorCode}: ${this.i18nService.translate(error.errorMessage, null, messages)}`; + message = error.cause ? `${message} - ${error.cause}` : message; + return new AddNotification( + new Notification( + NotificationType.Danger, + message, + 8000 + ) + ); + }) ); @Effect() createProviderFailEnableForm$ = this.actions$.pipe(