Skip to content

Commit

Permalink
Merged in bugfix/#8 (pull request #307)
Browse files Browse the repository at this point in the history
Bugfix/#8
  • Loading branch information
Jonathan Johnson committed Feb 28, 2019
2 parents e9682d0 + c0f64df commit 6886c70
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ResponseEntity<ErrorResponse> handleDatabaseConstraintViolation(Constrain

@ExceptionHandler(Exception.class)
public final ResponseEntity<ErrorResponse> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
22 changes: 14 additions & 8 deletions ui/src/app/metadata/provider/effect/collection.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
})
)
)
);
Expand All @@ -111,13 +113,17 @@ export class CollectionEffects {
ofType<AddProviderFail>(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(
Expand Down

0 comments on commit 6886c70

Please sign in to comment.