Commit 653fc890 authored by Marek Kadlečík's avatar Marek Kadlečík
Browse files

Set up 404 status when nonexistent player is requested

parent 91861072
......@@ -4,6 +4,7 @@ import cz.muni.fi.pa165.dto.PlayerDTO;
import cz.muni.fi.pa165.facade.PlayerFacade;
import cz.muni.fi.pa165.rest.RootUris;
import cz.muni.fi.pa165.rest.exception.ResourceAlreadyExistsException;
import cz.muni.fi.pa165.rest.exception.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -23,7 +24,12 @@ public class PlayerController {
@RequestMapping(value = "/{uuid}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public final PlayerDTO findById(@PathVariable("uuid") String uuid) {
return playerFacade.getPlayerById(uuid);
var playerDTO = playerFacade.getPlayerById(uuid);
if (playerDTO != null) {
return playerDTO;
} else {
throw new ResourceNotFoundException();
}
}
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
......
package cz.muni.fi.pa165.rest.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
* @author Marek Kadlečík
*/
@ResponseStatus(value=HttpStatus.NOT_FOUND, reason="The requested player was not found")
public class ResourceNotFoundException extends RuntimeException {
public ResourceNotFoundException() {
super(HttpStatus.NOT_FOUND.getReasonPhrase());
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment