1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.maxur.perfmodel.backend.rest;
17
18 import org.maxur.perfmodel.backend.domain.Incident;
19
20 import javax.ws.rs.WebApplicationException;
21 import javax.ws.rs.core.GenericEntity;
22 import javax.ws.rs.core.Response;
23 import java.util.List;
24
25 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
26 import static javax.ws.rs.core.Response.Status.*;
27 import static org.maxur.perfmodel.backend.domain.Incident.incidents;
28
29
30
31
32
33 public final class WebException extends WebApplicationException {
34
35 private static final long serialVersionUID = -2826609919565709334L;
36
37 private WebException(final Response.Status status, final String... messages) {
38 super(Response
39 .status(status)
40 .type(APPLICATION_JSON)
41 .entity(new GenericEntity<List<Incident>>(incidents(messages)) {
42 })
43 .build());
44 }
45
46 public static WebException notFoundException(final String... errors) {
47 return new WebException(NOT_FOUND, errors);
48 }
49
50 public static WebException badRequestException(final String... errors) {
51 return new WebException(BAD_REQUEST, errors);
52 }
53
54 public static WebException conflictException(final String... errors) {
55 return new WebException(CONFLICT, errors);
56 }
57
58
59 }