Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add human-readable MetasvcProblem.toString() #113

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Added

- The `Problem` (of error responses) is expanded by a hint that gives clearer information about the actual error
- User-friendly Problem's `toString()`
- The related entities of Manifestations and Works contain their name if they are `NamedEntity`s and are an instance
of the proper derived `Entity` class
- Add allowed media type "Object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Singular;
import org.zalando.problem.AbstractThrowableProblem;
Expand Down Expand Up @@ -65,4 +66,36 @@ public Date getTimestamp() {
public ProblemHint getHint() {
return hint;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder
.append("MetasvcProblem {")
.append("title=")
.append(getTitle())
.append(", type=")
.append(getType())
.append(", status=")
.append(getStatus())
.append(", instance=")
.append(getInstance())
.append(", hint=")
.append(getHint())
.append(", detail=")
.append(getDetail())
.append(", timestamp=")
.append(getTimestamp())
.append(", errors=")
.append(
getErrors() != null
? getErrors().stream()
.map(ValidationError::toString)
.collect(Collectors.joining(", ", "[", "]"))
: null)
.append(", parameters=")
.append(getParameters())
.append("}");
return builder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public enum ProblemHint {
public String getDescription() {
return description;
}

@Override
public String toString() {
return name() + " (" + description + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public String getFieldName() {
public String getMessageKey() {
return messageKey;
}

@Override
public String toString() {
return "ValidationError {fieldName=" + fieldName + ", messageKey=" + messageKey + "}";
}
}
Loading