Skip to content

Commit 78fb489

Browse files
committed
Json format exceptions
1 parent 3341a46 commit 78fb489

File tree

5 files changed

+71
-8
lines changed

5 files changed

+71
-8
lines changed

src/main/java/com/authlete/jaxrs/server/api/vci/BatchCredentialEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ private CredentialRequestInfo[] credentialBatchParse(final AuthleteApi api,
8484
switch (response.getAction())
8585
{
8686
case BAD_REQUEST:
87-
throw ExceptionUtil.badRequestException(content);
87+
throw ExceptionUtil.badRequestExceptionJson(content);
8888

8989
case UNAUTHORIZED:
9090
throw ExceptionUtil.unauthorizedException(accessToken, content);
9191

9292
case FORBIDDEN:
93-
throw ExceptionUtil.forbiddenException(content);
93+
throw ExceptionUtil.forbiddenExceptionJson(content);
9494

9595
case OK:
9696
return response.getInfo();

src/main/java/com/authlete/jaxrs/server/api/vci/CredentialEndpoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@ private CredentialRequestInfo credentialSingleParse(final AuthleteApi api,
8282
switch (response.getAction())
8383
{
8484
case BAD_REQUEST:
85-
throw ExceptionUtil.badRequestException(content);
85+
throw ExceptionUtil.badRequestExceptionJson(content);
8686

8787
case UNAUTHORIZED:
8888
throw ExceptionUtil.unauthorizedException(accessToken, content);
8989

9090
case FORBIDDEN:
91-
throw ExceptionUtil.forbiddenException(content);
91+
throw ExceptionUtil.forbiddenExceptionJson(content);
9292

9393
case OK:
9494
return response.getInfo();
9595

9696
case INTERNAL_SERVER_ERROR:
9797
default:
98-
throw ExceptionUtil.internalServerErrorException(content);
98+
throw ExceptionUtil.internalServerErrorExceptionJson(content);
9999
}
100100
}
101101

src/main/java/com/authlete/jaxrs/server/api/vci/DeferredCredentialEndpoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,20 @@ private CredentialRequestInfo credentialDeferredParse(final AuthleteApi api,
8989
switch (response.getAction())
9090
{
9191
case BAD_REQUEST:
92-
throw ExceptionUtil.badRequestException(content);
92+
throw ExceptionUtil.badRequestExceptionJson(content);
9393

9494
case UNAUTHORIZED:
9595
throw ExceptionUtil.unauthorizedException(accessToken, content);
9696

9797
case FORBIDDEN:
98-
throw ExceptionUtil.forbiddenException(content);
98+
throw ExceptionUtil.forbiddenExceptionJson(content);
9999

100100
case OK:
101101
return response.getInfo();
102102

103103
case INTERNAL_SERVER_ERROR:
104104
default:
105-
throw ExceptionUtil.internalServerErrorException(content);
105+
throw ExceptionUtil.internalServerErrorExceptionJson(content);
106106
}
107107
}
108108

src/main/java/com/authlete/jaxrs/server/util/ExceptionUtil.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919

2020
import static com.authlete.jaxrs.server.util.ResponseUtil.badRequest;
21+
import static com.authlete.jaxrs.server.util.ResponseUtil.badRequestJson;
22+
import static com.authlete.jaxrs.server.util.ResponseUtil.forbidden;
2123
import static com.authlete.jaxrs.server.util.ResponseUtil.forbiddenJson;
2224
import static com.authlete.jaxrs.server.util.ResponseUtil.internalServerErrorJson;
2325
import static com.authlete.jaxrs.server.util.ResponseUtil.unauthorized;
@@ -49,6 +51,22 @@ public static WebApplicationException badRequestException(String entity)
4951
}
5052

5153

54+
/**
55+
* Create an exception indicating "400 Bad Request" in application/json format.
56+
*
57+
* @param entity
58+
* An entity to contain in the response of the exception.
59+
*
60+
* @return
61+
* An exception indicating "400 Bad Request".
62+
*/
63+
public static WebApplicationException badRequestExceptionJson(String entity)
64+
{
65+
return new WebApplicationException(entity, badRequestJson(entity));
66+
}
67+
68+
69+
5270
/**
5371
* Create an exception indicating "400 Bad Request".
5472
*
@@ -111,6 +129,21 @@ public static WebApplicationException unauthorizedException(Viewable entity, Str
111129
* An exception indicating "403 Forbidden".
112130
*/
113131
public static WebApplicationException forbiddenException(final String entity)
132+
{
133+
return new WebApplicationException(entity, forbidden(entity));
134+
}
135+
136+
137+
/**
138+
* Create an exception indicating "403 Forbidden" in application/json format.
139+
*
140+
* @param entity
141+
* An entity to contain in the response of the exception.
142+
*
143+
* @return
144+
* An exception indicating "403 Forbidden".
145+
*/
146+
public static WebApplicationException forbiddenExceptionJson(final String entity)
114147
{
115148
return new WebApplicationException(entity, forbiddenJson(entity));
116149
}

src/main/java/com/authlete/jaxrs/server/util/ResponseUtil.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ public static Response badRequest(String entity)
139139
}
140140

141141

142+
/**
143+
* Build an "application/json" response of "400 Bad Request".
144+
*
145+
* @param entity
146+
* A string entity to contain in the response.
147+
*
148+
* @return
149+
* An "application/json" response of "400 Bad Request".
150+
*/
151+
public static Response badRequestJson(String entity)
152+
{
153+
return builderForJson(Status.BAD_REQUEST, entity).build();
154+
}
155+
156+
142157
/**
143158
* Build a "text/html" response of "400 Bad Request".
144159
*
@@ -194,6 +209,21 @@ public static Response unauthorized(Viewable entity, String challenge)
194209
}
195210

196211

212+
/**
213+
* Build a "text/plain" response of "403 Forbidden".
214+
*
215+
* @param entity
216+
* A string entity to contain in the response.
217+
*
218+
* @return
219+
* An "text/plain" response of "403 Forbidde".
220+
*/
221+
public static Response forbidden(final String entity)
222+
{
223+
return builderForTextPlain(Status.FORBIDDEN, entity).build();
224+
}
225+
226+
197227
/**
198228
* Build an "application/json" response of "403 Forbidden".
199229
*

0 commit comments

Comments
 (0)