001/*
002 * acme4j - Java ACME client
003 *
004 * Copyright (C) 2015 Richard "Shred" Körber
005 *   http://acme4j.shredzone.org
006 *
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
013 */
014package org.shredzone.acme4j.exception;
015
016import java.net.URI;
017import java.util.Objects;
018
019import org.shredzone.acme4j.Problem;
020
021/**
022 * An exception that is thrown when the ACME server returned an error. It contains
023 * further details of the cause.
024 */
025public class AcmeServerException extends AcmeException {
026    private static final long serialVersionUID = 5971622508467042792L;
027
028    private final Problem problem;
029
030    /**
031     * Creates a new {@link AcmeServerException}.
032     *
033     * @param problem
034     *            {@link Problem} that caused the exception
035     */
036    public AcmeServerException(Problem problem) {
037        super(Objects.requireNonNull(problem).toString());
038        this.problem = problem;
039    }
040
041    /**
042     * Returns the error type.
043     */
044    public URI getType() {
045        return problem.getType();
046    }
047
048    /**
049     * Returns the {@link Problem} that caused the exception
050     */
051    public Problem getProblem() {
052        return problem;
053    }
054
055}