All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.internal.errors.SphereErrorResponse Maven / Gradle / Ivy

There is a newer version: 0.72.1
Show newest version
package io.sphere.internal.errors;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import io.sphere.client.SphereError;

import javax.annotation.Nonnull;
import java.util.List;

/** Response object returned by the Sphere Projects Web Service in case of an error.
 *  @see API documentation */
public class SphereErrorResponse {
    private int statusCode;
    private String message = "";
    @Nonnull private List errors = ImmutableList.of();

    // for JSON deserializer
    private SphereErrorResponse() {}

    private SphereErrorResponse(final int statusCode) {
        this.statusCode = statusCode;
    }

    /** The HTTP status code. */
    public int getStatusCode() { return statusCode; }

    /** The message of the first error, for convenience. */
    public String getMessage() { return message; }

    /** The individual errors. */
    @Nonnull public List getErrors() { return errors; }

    @Override public String toString() {
        return String.format("[" + getStatusCode() + "]" + "\n  " + Joiner.on("\n  ").join(getErrors()));
    }

    public static SphereErrorResponse of(final int statusCode) {
        return new SphereErrorResponse(statusCode);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy