Skip to content

Commit

Permalink
Use MetasvcProblem in ExceptionAdvice
Browse files Browse the repository at this point in the history
…instead of zalando's `Problem`
  • Loading branch information
daforster committed Apr 22, 2024
1 parent 181afa8 commit b05b273
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -70,7 +71,7 @@ public ResponseEntity<Problem> handleNotFound(
public ResponseEntity<Problem> handleValidationException(
ValidationException exception, ServletWebRequest request) {
ThrowableProblem problem =
Problem.builder()
MetasvcProblem.builder()
.withType(
UriComponentsBuilder.fromPath("/errors/")
.path(exception.getClass().getSimpleName())
Expand All @@ -80,9 +81,9 @@ public ResponseEntity<Problem> 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);
}
Expand All @@ -94,7 +95,7 @@ public ResponseEntity<Problem> handleAllOther(Exception exception, ServletWebReq
cause = cause.getCause();
}
ThrowableProblem problem =
Problem.builder()
MetasvcProblem.builder()
.withType(
UriComponentsBuilder.fromPath("/errors/")
.path(cause.getClass().getSimpleName())
Expand All @@ -104,7 +105,8 @@ public ResponseEntity<Problem> 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);
Expand Down

0 comments on commit b05b273

Please sign in to comment.