Skip to content

Instantly share code, notes, and snippets.

@abdulbasitkay
Created May 4, 2017 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdulbasitkay/d22a8cd94f63ec27689d4fd2ecb2877f to your computer and use it in GitHub Desktop.
Save abdulbasitkay/d22a8cd94f63ec27689d4fd2ecb2877f to your computer and use it in GitHub Desktop.
Question Resource with error handling
@Path("questions/")
public class QuestionResource {
@GET
@Path("{id}")
@Produces("application/json")
Response getQuestion(@PathParam("id") String questionId) {
QuestionDto question = questionService.getQuestionById(questionId);
if (question == null)
throw new ApiException(404, "Question not found", "Make sure the Id is valid and a question has been created");
return Response.status(OK).entity(question).build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment