diff --git a/pom.xml b/pom.xml index 0eb9a4b..82a56d1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.gw2auth oauth2-server - 1.73.1 + 1.74.0 jar diff --git a/src/main/java/com/gw2auth/oauth2/server/web/CustomErrorController.java b/src/main/java/com/gw2auth/oauth2/server/web/CustomErrorController.java new file mode 100644 index 0000000..ab5befe --- /dev/null +++ b/src/main/java/com/gw2auth/oauth2/server/web/CustomErrorController.java @@ -0,0 +1,49 @@ +package com.gw2auth.oauth2.server.web; + +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController; +import org.springframework.boot.web.error.ErrorAttributeOptions; +import org.springframework.boot.web.servlet.error.ErrorAttributes; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.util.UriComponentsBuilder; + +import java.util.Map; + +@RestController +public class CustomErrorController extends AbstractErrorController { + + @Autowired + public CustomErrorController(ErrorAttributes errorAttributes) { + super(errorAttributes); + } + + @GetMapping("/error") + public ResponseEntity error(HttpServletRequest request) { + final Map attributes = getErrorAttributes(request, getErrorAttributeOptions()); + + return ResponseEntity.status(HttpStatus.FOUND) + .location( + UriComponentsBuilder + .fromUriString(request.getRequestURI()) + .replacePath("/error") + .queryParam("status", attributes.get("status")) + .queryParam("error", attributes.get("error")) + .queryParam("message", attributes.get("message")) + .queryParam("path", attributes.get("path")) + .build() + .toUri() + ) + .build(); + } + + protected ErrorAttributeOptions getErrorAttributeOptions() { + return ErrorAttributeOptions.defaults() + .including(ErrorAttributeOptions.Include.EXCEPTION) + .including(ErrorAttributeOptions.Include.MESSAGE) + .including(ErrorAttributeOptions.Include.PATH); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 064075d..716153d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -19,6 +19,12 @@ com.gw2auth: interval: ${GW2AUTH_TOKEN_VALID_CHECK_INTERVAL} ignore-after: ${GW2AUTH_TOKEN_VALID_CHECK_IGNORE_AFTER} +server: + error: + path: '/error' + whitelabel: + enabled: false + spring: datasource: url: "jdbc:postgresql://${SERVER_POSTGRES_HOST}:${SERVER_POSTGRES_PORT}/${SERVER_POSTGRES_DB}${SERVER_POSTGRES_OPTIONS}"