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.time.Instant; 018import java.util.Collection; 019import java.util.Collections; 020 021/** 022 * An exception that is thrown when a rate limit was exceeded. 023 */ 024public class AcmeRateLimitExceededException extends AcmeServerException { 025 private static final long serialVersionUID = 4150484059796413069L; 026 027 private final Instant retryAfter; 028 private final Collection<URI> documents; 029 030 /** 031 * Creates a new {@link AcmeRateLimitExceededException}. 032 * 033 * @param type 034 * System readable error type (here 035 * {@code "urn:ietf:params:acme:error:rateLimited"}) 036 * @param detail 037 * Human readable error message 038 * @param retryAfter 039 * The moment the request is expected to succeed again, may be {@code null} 040 * if not known 041 * @param documents 042 * URIs pointing to documents about the rate limit that was hit 043 */ 044 public AcmeRateLimitExceededException(String type, String detail, Instant retryAfter, Collection<URI> documents) { 045 super(type, detail); 046 this.retryAfter = retryAfter; 047 this.documents = 048 documents != null ? Collections.unmodifiableCollection(documents) : null; 049 } 050 051 /** 052 * Returns the moment the request is expected to succeed again. {@code null} if this 053 * moment is not known. 054 */ 055 public Instant getRetryAfter() { 056 return retryAfter; 057 } 058 059 /** 060 * Collection of URIs pointing to documents about the rate limit that was hit. 061 * {@code null} if the server did not provide such URIs. 062 */ 063 public Collection<URI> getDocuments() { 064 return documents; 065 } 066 067}