Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
simple controller: return bad request if no or invalid verification m…
Browse files Browse the repository at this point in the history
…ode is provided
  • Loading branch information
gstoehld committed Jan 31, 2022
1 parent 5d524ad commit ec775da
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public SimpleController(VerificationService verificationService) {
@PostMapping("/verify")
public @ResponseBody SimpleVerificationResponse verify(@RequestBody SimpleControllerPayload hCertPayload) {
String verificationMode = hCertPayload.getMode();
if(!getVerificationModes().contains(verificationMode)){
throw new IllegalArgumentException("Invalid or no verification mode provided. Query /modes for currently available modes");
}
final var start = Instant.now();

// Decode hcert
Expand Down Expand Up @@ -89,10 +92,20 @@ public SimpleController(VerificationService verificationService) {
}


@ExceptionHandler(DecodingException.class)
@ExceptionHandler(DecodingException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<String> invalidHCert(DecodingException e) {
logger.info("Decoding exception thrown: {}", e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMsg());
}
}

@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<String> invalidMode(IllegalArgumentException e) {
logger.info("IllegalArgumentException thrown: {}", e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}


}

0 comments on commit ec775da

Please sign in to comment.