Skip to content

Instantly share code, notes, and snippets.

@albertoaflores
Last active March 4, 2017 11:25
Show Gist options
  • Save albertoaflores/3bc4706e97c158e91117cef7ee13d9fe to your computer and use it in GitHub Desktop.
Save albertoaflores/3bc4706e97c158e91117cef7ee13d9fe to your computer and use it in GitHub Desktop.
Sample REST endpoint with non 200 response and no Exception
@RequestMapping("/{surveyId}")
public Survey findSurvey(@PathVariable String surveyId, HttpServletResponse response) {
log.info("Querying survey {}", surveyId);
Survey survey = repository.get(surveyId);
if (survey == null) {
log.warn("Survey {} was not found!", surveyId);
response.setStatus(404);
}
return survey;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment