Error Class — spring-boot Architecture
Architecture documentation for the Error class in Error.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/main/java/org/springframework/boot/web/error/Error.java lines 40–121
public final class Error implements MessageSourceResolvable {
private final MessageSourceResolvable cause;
/**
* Create a new {@code Error} instance with the specified cause.
* @param cause the error cause (must not be {@code null})
*/
private Error(MessageSourceResolvable cause) {
Assert.notNull(cause, "'cause' must not be null");
this.cause = cause;
}
@Override
public String @Nullable [] getCodes() {
return this.cause.getCodes();
}
@Override
public Object @Nullable [] getArguments() {
return this.cause.getArguments();
}
@Override
public @Nullable String getDefaultMessage() {
return this.cause.getDefaultMessage();
}
/**
* Return the original cause of the error.
* @return the error cause
*/
@JsonIgnore
public MessageSourceResolvable getCause() {
return this.cause;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
return Objects.equals(this.cause, ((Error) obj).cause);
}
@Override
public int hashCode() {
return Objects.hash(this.cause);
}
@Override
public String toString() {
return this.cause.toString();
}
/**
* Wrap the given errors, if necessary, such that they are suitable for serialization
* to JSON. {@link MessageSourceResolvable} implementations that are known to be
* suitable are not wrapped.
* @param errors the errors to wrap
* @return a new Error list
* @since 3.5.4
*/
public static List<MessageSourceResolvable> wrapIfNecessary(List<? extends MessageSourceResolvable> errors) {
if (CollectionUtils.isEmpty(errors)) {
return Collections.emptyList();
}
List<MessageSourceResolvable> result = new ArrayList<>(errors.size());
for (MessageSourceResolvable error : errors) {
result.add(requiresWrapping(error) ? new Error(error) : error);
}
return List.copyOf(result);
}
private static boolean requiresWrapping(MessageSourceResolvable error) {
return !(error instanceof ObjectError);
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free