Skip to content

Commit

Permalink
[SHIBUI-1063]
Browse files Browse the repository at this point in the history
Relocated the JsonSchemaValidationFailedException because it wasn't
being called in the groovy controller advice class. The generic
exception handler was handling it instead.

Also fixed handling of the List<Object> -> List<String> conversion.

Json schema validation errors should return something more useful now.
  • Loading branch information
Bill Smith committed Jan 24, 2019
1 parent 3c9063f commit 67c33c1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ class RelyingPartyOverridesJsonSchemaValidatingControllerAdvice extends RequestB
] as HttpInputMessage
}

@ExceptionHandler(JsonSchemaValidationFailedException)
final ResponseEntity<?> handleJsonSchemaValidationFailedException(JsonSchemaValidationFailedException ex) {
ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse("400", String.join('\n', ex.errors)))
}

@PostConstruct
void init() {
this.jsonSchemaLocation = metadataSourcesSchema(this.jsonSchemaResourceLocationRegistry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.internet2.tier.shibboleth.admin.ui.controller.ErrorResponse;
import edu.internet2.tier.shibboleth.admin.ui.domain.exceptions.MetadataFileNotFoundException;
import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.MetadataResolver;
import edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaValidationFailedException;
import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -12,8 +13,8 @@
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.client.HttpClientErrorException;

import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.NOT_FOUND;

/**
Expand Down Expand Up @@ -56,4 +57,9 @@ public final ResponseEntity<ErrorResponse> metadataFileNotFoundHandler(MetadataF
ErrorResponse errorResponse = new ErrorResponse(INTERNAL_SERVER_ERROR.toString(), ex.getLocalizedMessage());
return new ResponseEntity<>(errorResponse, INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(JsonSchemaValidationFailedException.class)
public final ResponseEntity<?> handleJsonSchemaValidationFailedException(JsonSchemaValidationFailedException ex) {
return ResponseEntity.status(BAD_REQUEST).body(new ErrorResponse("400", String.join("\n", ex.getErrors())));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package edu.internet2.tier.shibboleth.admin.ui.jsonschema;

import lombok.Getter;

import java.util.List;

/**
Expand All @@ -8,11 +10,12 @@
*
* @author Dmitriy Kopylenko
*/
class JsonSchemaValidationFailedException extends RuntimeException {
@Getter
public class JsonSchemaValidationFailedException extends RuntimeException {

List<String> errors;

JsonSchemaValidationFailedException(List<String> errors) {
this.errors = errors;
JsonSchemaValidationFailedException(List<?> errors) {
this.errors = (List<String>) errors;
}
}

0 comments on commit 67c33c1

Please sign in to comment.