From b05b27345a9394023127f70ca5d90233a327bd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20F=C3=B6rster?= Date: Mon, 22 Apr 2024 20:11:34 +0200 Subject: [PATCH] Use `MetasvcProblem` in `ExceptionAdvice` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …instead of zalando's `Problem` --- .../exceptions/RepositoryException.java | 3 ++- .../impl/jdbi/UniqueObjectRepositoryImpl.java | 2 +- .../controller/advice/ExceptionAdvice.java | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/metasvc-server/backend-api/src/main/java/io/github/dbmdz/metadata/server/backend/api/repository/exceptions/RepositoryException.java b/metasvc-server/backend-api/src/main/java/io/github/dbmdz/metadata/server/backend/api/repository/exceptions/RepositoryException.java index 23b90763b..d00bd205a 100644 --- a/metasvc-server/backend-api/src/main/java/io/github/dbmdz/metadata/server/backend/api/repository/exceptions/RepositoryException.java +++ b/metasvc-server/backend-api/src/main/java/io/github/dbmdz/metadata/server/backend/api/repository/exceptions/RepositoryException.java @@ -1,6 +1,7 @@ package io.github.dbmdz.metadata.server.backend.api.repository.exceptions; -import de.digitalcollections.model.exception.ProblemHinting; +import de.digitalcollections.model.exception.problem.ProblemHint; +import de.digitalcollections.model.exception.problem.ProblemHinting; public class RepositoryException extends Exception implements ProblemHinting { diff --git a/metasvc-server/backend-jdbi/src/main/java/io/github/dbmdz/metadata/server/backend/impl/jdbi/UniqueObjectRepositoryImpl.java b/metasvc-server/backend-jdbi/src/main/java/io/github/dbmdz/metadata/server/backend/impl/jdbi/UniqueObjectRepositoryImpl.java index cae0ead9d..88fb4afeb 100644 --- a/metasvc-server/backend-jdbi/src/main/java/io/github/dbmdz/metadata/server/backend/impl/jdbi/UniqueObjectRepositoryImpl.java +++ b/metasvc-server/backend-jdbi/src/main/java/io/github/dbmdz/metadata/server/backend/impl/jdbi/UniqueObjectRepositoryImpl.java @@ -1,7 +1,7 @@ package io.github.dbmdz.metadata.server.backend.impl.jdbi; import de.digitalcollections.model.UniqueObject; -import de.digitalcollections.model.exception.ProblemHinting.ProblemHint; +import de.digitalcollections.model.exception.problem.ProblemHint; import de.digitalcollections.model.list.filtering.FilterCriterion; import de.digitalcollections.model.list.filtering.Filtering; import de.digitalcollections.model.list.paging.PageRequest; diff --git a/metasvc-server/webapp/src/main/java/io/github/dbmdz/metadata/server/controller/advice/ExceptionAdvice.java b/metasvc-server/webapp/src/main/java/io/github/dbmdz/metadata/server/controller/advice/ExceptionAdvice.java index 801d73e3e..d5db90874 100644 --- a/metasvc-server/webapp/src/main/java/io/github/dbmdz/metadata/server/controller/advice/ExceptionAdvice.java +++ b/metasvc-server/webapp/src/main/java/io/github/dbmdz/metadata/server/controller/advice/ExceptionAdvice.java @@ -1,7 +1,8 @@ package io.github.dbmdz.metadata.server.controller.advice; -import de.digitalcollections.model.exception.ProblemHinting; -import de.digitalcollections.model.exception.ProblemHinting.ProblemHint; +import de.digitalcollections.model.exception.problem.MetasvcProblem; +import de.digitalcollections.model.exception.problem.ProblemHint; +import de.digitalcollections.model.exception.problem.ProblemHinting; import de.digitalcollections.model.validation.ValidationException; import io.github.dbmdz.metadata.server.business.api.service.exceptions.ConflictException; import io.github.dbmdz.metadata.server.business.api.service.exceptions.ResourceNotFoundException; @@ -70,7 +71,7 @@ public ResponseEntity handleNotFound( public ResponseEntity handleValidationException( ValidationException exception, ServletWebRequest request) { ThrowableProblem problem = - Problem.builder() + MetasvcProblem.builder() .withType( UriComponentsBuilder.fromPath("/errors/") .path(exception.getClass().getSimpleName()) @@ -80,9 +81,9 @@ public ResponseEntity handleValidationException( .withStatus(statusFromExceptionClass(exception)) .withInstance(getRequestUri(request)) .withDetail(exception.getMessage()) - .with("errors", exception.getErrors()) - .with("timestamp", new Date()) - .with("hint", exception.getHint()) + .withErrors(exception.getErrors()) + .withTimestamp(new Date()) + .withHint(exception.getHint()) .build(); return create(problem, request); } @@ -94,7 +95,7 @@ public ResponseEntity handleAllOther(Exception exception, ServletWebReq cause = cause.getCause(); } ThrowableProblem problem = - Problem.builder() + MetasvcProblem.builder() .withType( UriComponentsBuilder.fromPath("/errors/") .path(cause.getClass().getSimpleName()) @@ -104,7 +105,8 @@ public ResponseEntity handleAllOther(Exception exception, ServletWebReq .withStatus(statusFromExceptionClass(cause)) .withDetail(cause.getMessage()) .withInstance(getRequestUri(request)) - .with("hint", hintFromException(exception)) + .withHint(hintFromException(exception)) + .withTimestamp(new Date()) .build(); if (problem.getStatus() == Status.INTERNAL_SERVER_ERROR) LOGGER.error("Exception stack trace", exception);