parent
a0998d2edf
commit
3b92f0b834
|
@ -34,7 +34,7 @@ public class StocksResource {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response get(@PathParam("ticker") String id) {
|
public Response get(@PathParam("ticker") String id) {
|
||||||
Optional<Stock> stock = stocks.findById(id);
|
Optional<Stock> stock = stocks.findById(id);
|
||||||
stock.orElseThrow(IllegalArgumentException::new);
|
stock.orElseThrow(() -> new IllegalArgumentException("ticker"));
|
||||||
|
|
||||||
return Response.ok(stock.get())
|
return Response.ok(stock.get())
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -7,7 +7,7 @@ import javax.ws.rs.core.Response.Status;
|
||||||
import javax.ws.rs.ext.ExceptionMapper;
|
import javax.ws.rs.ext.ExceptionMapper;
|
||||||
|
|
||||||
public class ServerExceptionMapper implements ExceptionMapper<WebApplicationException> {
|
public class ServerExceptionMapper implements ExceptionMapper<WebApplicationException> {
|
||||||
public static final String HTTP_405_MESSAGE = "METHOD_NOT_ALLOWED";
|
public static final String HTTP_405_MESSAGE = "use one of";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response toResponse(final WebApplicationException exception) {
|
public Response toResponse(final WebApplicationException exception) {
|
||||||
|
@ -18,7 +18,7 @@ public class ServerExceptionMapper implements ExceptionMapper<WebApplicationExce
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case METHOD_NOT_ALLOWED:
|
case METHOD_NOT_ALLOWED:
|
||||||
message = HTTP_405_MESSAGE;
|
message = HTTP_405_MESSAGE + response.getAllowedMethods();
|
||||||
break;
|
break;
|
||||||
case INTERNAL_SERVER_ERROR:
|
case INTERNAL_SERVER_ERROR:
|
||||||
message = "internal validation - " + exception;
|
message = "internal validation - " + exception;
|
||||||
|
|
Loading…
Reference in New Issue