Skip to content
Snippets Groups Projects
Commit 28be8d5d authored by Martin Vogel's avatar Martin Vogel
Browse files

#414 Add custom problems to wrap exceptions

parent 6f8c7fa8
No related branches found
No related tags found
2 merge requests!2#414 Remaining changes from MR,!1planning#414 Methoden Signaturen (Zwischenstand)
package fitconnect.api.problems;
import org.zalando.problem.Status;
public class DecryptionProblem extends FitConnectProblem {
private static final long serialVersionUID = 1L;
public DecryptionProblem(String issue) {
super(
makeProblemURI("invalid-jwe-content"),
"Invalid JWE Content",
Status.BAD_REQUEST,
"There was a problem parsing the JWE",
null,
issue
);
}
}
package fitconnect.api.problems;
import org.zalando.problem.Status;
public class EncryptionProblem extends FitConnectProblem {
private static final long serialVersionUID = 1L;
public EncryptionProblem(String issue) {
super(
makeProblemURI("invalid-jwe-content"),
"Invalid JWE Content",
Status.BAD_REQUEST,
"There was a problem parsing the JWE",
null,
issue
);
}
}
package fitconnect.api.problems;
import fitconnect.api.schema.FitConnectSchemaScopes;
import org.zalando.problem.StatusType;
import org.zalando.problem.ThrowableProblem;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
public class FitConnectProblem extends ThrowableProblem {
private static final long serialVersionUID = 1L;
private final URI type;
private final String title;
private final StatusType status;
private final String detail;
private final URI instance;
private final String issue;
protected FitConnectProblem(URI type, String title, StatusType status) {
this(type, title, status, null, null, null);
}
protected FitConnectProblem(URI type, String title, StatusType status, String detail, URI instance, String issue) {
this.type = type;
this.title = title;
this.status = status;
this.detail = detail;
this.instance = instance;
this.issue = issue;
}
public static URI makeProblemURI(String problemName) {
return URI.create(FitConnectSchemaScopes.PROBLEMS_BASE_URI + problemName);
}
@Override
public URI getType() {
return type;
}
@Override
public String getTitle() {
return title;
}
@Override
public StatusType getStatus() {
return status;
}
@Override
public String getDetail() {
return detail;
}
@Override
public URI getInstance() {
return instance;
}
@Override
public Map<String, Object> getParameters() {
return issue == null ? Collections.emptyMap() : Map.of("issue", issue);
}
}
package fitconnect.api.schema;
public final class FitConnectSchemaScopes {
// Schema-Basis-URI für alle Services
private static final String BASE_URI = "https://schema.fitko.de/fit-connect";
// Events sind nicht API-spezifisch
public static final String EVENTS_BASE_URI = BASE_URI + "/events/";
// API-spezifische Schema-Basis-URI
private static final String API_BASE_URI = BASE_URI + "/submission-api";
// Callbacks sind API-spezifisch
public static final String CALLBACKS_BASE_URI = API_BASE_URI + "/callbacks/";
// Problems sind API-spezifisch
public static final String PROBLEMS_BASE_URI = API_BASE_URI + "/problems/";
// API-spezifische Schema-Basis-URI
private static final String SET_BASE_URI = BASE_URI + "/set-payload";
// static class only for constants
private FitConnectSchemaScopes() {
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment