001/*
002 * acme4j - Java ACME client
003 *
004 * Copyright (C) 2016 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.time.Instant;
017import java.util.Objects;
018
019import org.shredzone.acme4j.AcmeJsonResource;
020
021/**
022 * A server side process has not been completed yet. The server also provides an estimate
023 * of when the process is expected to complete.
024 * <p>
025 * Note: Prefer to use {@link AcmeJsonResource#fetch()}. Invoking
026 * {@link AcmeJsonResource#update()} and catching this exception is unnecessary
027 * complicated and a legacy from acme4j v2 which will disappear in a future release.
028 */
029public class AcmeRetryAfterException extends AcmeException {
030    private static final long serialVersionUID = 4461979121063649905L;
031
032    private final Instant retryAfter;
033
034    /**
035     * Creates a new {@link AcmeRetryAfterException}.
036     *
037     * @param msg
038     *            Error details
039     * @param retryAfter
040     *            retry-after date returned by the server
041     */
042    public AcmeRetryAfterException(String msg, Instant retryAfter) {
043        super(msg);
044        this.retryAfter = Objects.requireNonNull(retryAfter);
045    }
046
047    /**
048     * Returns the retry-after instant returned by the server. This is only an estimate
049     * of when a retry attempt might succeed.
050     */
051    public Instant getRetryAfter() {
052        return retryAfter;
053    }
054
055}