![JAR search and dependency download from the Maven repository](/logo.png)
com.yahoo.elide.ElideError Maven / Gradle / Ivy
/*
* Copyright 2023, the original author or authors.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide;
import lombok.Getter;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Consumer;
/**
* Represents an error that can later be mapped to the more specific
* JsonApiError or GraphQLError.
*
* @see ElideErrors
*/
@Getter
public class ElideError {
/**
* The error message. For JSON-API this will be mapped to the details member and
* for GraphQL this will be mapped to the message member.
*/
private final String message;
/**
* Additional attributes about the error. For JSON-API this will be mapped to the
* meta member and for GraphQL this will be mapped to the extensions member.
*/
private final Map attributes;
public ElideError(String message, Map attributes) {
this.message = message;
this.attributes = attributes;
}
/**
* Returns a mutable {@link ElideErrorBuilder} for building {@link ElideError}.
*
* @return the builder
*/
public static ElideErrorBuilder builder() {
return new ElideErrorBuilder();
}
/**
* A mutable builder for building {@link ElideError}.
*/
public static class ElideErrorBuilder {
private String message;
private Map attributes = new LinkedHashMap<>();
/**
* Sets the message of the error.
*
* For JSON-API this will be mapped to the details member and for GraphQL this
* will be mapped to the message member.
*
* @param message the message
* @return the builder
*/
public ElideErrorBuilder message(String message) {
this.message = message;
return this;
}
/**
* Sets the attributes.
*
* @param attributes the attributes to set
* @return the builder
*/
public ElideErrorBuilder attributes(Map attributes) {
this.attributes = attributes;
return this;
}
/**
* Customize the attributes.
*
* @param attributes the customizer
* @return the builder
*/
public ElideErrorBuilder attributes(Consumer