Skip to content

Commit

Permalink
Error messages improved
Browse files Browse the repository at this point in the history
  • Loading branch information
mbuechner committed Feb 24, 2021
1 parent 44894a2 commit 62d519f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/de/ddb/labs/ef2so/Ef2soService.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ public Response getRoot(@Context HttpHeaders headers) {
@Produces(MediaType.APPLICATION_JSON)
public Response get(@Context HttpHeaders headers, @PathParam("idn") String idn) {
try {

if (idn.isBlank()) {
throw new InvalidParameterException("No IDN passed");
}
if (!gndIdnPattern.matcher(idn).matches()) {
throw new InvalidParameterException("Invalid IDN given.");
throw new InvalidParameterException("Invalid IDN passed");
}
LOG.info("Execute request for IDN '{}'...", idn);
final URL url = new URL(EF_URL + idn);
Expand Down Expand Up @@ -105,7 +107,7 @@ public Response get(@Context HttpHeaders headers, @PathParam("idn") String idn)
if (result.isEmpty()) {
return Response
.status(501)
.entity("{\"Error\":\"Requested resource '" + idn + "' NOT supported by Schema.org.\"}")
.entity("{\"Error\":\"Requested resource '" + idn + "' is NOT supported by Schema.org\"}")
.build();
}

Expand All @@ -115,7 +117,7 @@ public Response get(@Context HttpHeaders headers, @PathParam("idn") String idn)
.build();

} catch (Exception e) {
LOG.error(e.getLocalizedMessage(), e);
LOG.error(e.getMessage(), e);
return Response
.status(500)
.entity("{\"Error\":\"" + e.getMessage() + "\"}")
Expand Down

0 comments on commit 62d519f

Please sign in to comment.