Skip to content

Commit

Permalink
JSON 404,405 messsages for the API part of the app (re: #3235)
Browse files Browse the repository at this point in the history
  • Loading branch information
michbarsinai committed Oct 23, 2016
1 parent 66cdb19 commit dff1f32
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,15 @@ public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) thr
return;
}
}
fc.doFilter(sr, sr1);
try {
fc.doFilter(sr, sr1);
} catch ( ServletException se ) {
logger.log(Level.WARNING, "Error processing " + requestURI +": " + se.getMessage(), se);
HttpServletResponse resp = (HttpServletResponse) sr1;
resp.setStatus(500);
resp.setHeader("PROCUDER", "ApiBlockingFilter");
resp.getWriter().append("Error: " + se.getMessage());
}
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/TestApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.ejb.EJB;
import javax.json.Json;
import javax.json.JsonObjectBuilder;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.QueryParam;
import org.mindrot.jbcrypt.BCrypt;

Expand Down Expand Up @@ -144,4 +145,10 @@ public Response getIpGroupsContaining( @PathParam("address") String addrStr ) {
}
}


@Path("/notFound/{thing}")
@GET
public Response throwNotFound( @PathParam("thing") String thing ) {
throw new NotFoundException("Can't find the " + thing);
}
}

0 comments on commit dff1f32

Please sign in to comment.