mirror of
https://github.com/ysoftdevs/oauth-playground-server.git
synced 2026-03-20 00:04:55 +01:00
DAG authorization pending - now correctly in JSON
This commit is contained in:
@@ -2,24 +2,37 @@ package com.ysoft.geecon.error;
|
||||
|
||||
import io.quarkus.qute.CheckedTemplate;
|
||||
import io.quarkus.qute.TemplateInstance;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.container.ResourceInfo;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ApplicationScoped
|
||||
class ExceptionMappers {
|
||||
@ServerExceptionMapper
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response mapJson(OAuthException exception) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(exception.getResponse()).build();
|
||||
}
|
||||
@Inject
|
||||
ResourceInfo resourceInfo;
|
||||
|
||||
@ServerExceptionMapper
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response mapHtml(OAuthException exception) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(Templates.error(exception.getResponse())).build();
|
||||
public Response exception(OAuthException exception) {
|
||||
Object entity = producesJson() ? exception.getResponse() : Templates.error(exception.getResponse());
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(entity).build();
|
||||
}
|
||||
|
||||
private boolean producesJson() {
|
||||
Produces annotation = resourceInfo.getResourceMethod().getAnnotation(Produces.class);
|
||||
if (annotation == null) {
|
||||
return false;
|
||||
}
|
||||
String[] produces = annotation.value();
|
||||
return Arrays.asList(produces).contains(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
|
||||
@CheckedTemplate
|
||||
public static class Templates {
|
||||
public static native TemplateInstance error(OAuthException.ErrorResponse response);
|
||||
|
||||
Reference in New Issue
Block a user