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.util.Objects; 017 018import org.shredzone.acme4j.toolbox.AcmeUtils; 019 020/** 021 * An exception that is thrown when the ACME server returned an error. It contains 022 * further details of the cause. 023 */ 024public class AcmeServerException extends AcmeException { 025 private static final long serialVersionUID = 5971622508467042792L; 026 027 private final String type; 028 029 /** 030 * Creates a new {@link AcmeServerException}. 031 * 032 * @param type 033 * System readable error type (e.g. 034 * {@code "urn:ietf:params:acme:error:malformed"}) 035 * @param detail 036 * Human readable error message 037 */ 038 public AcmeServerException(String type, String detail) { 039 super(detail); 040 this.type = Objects.requireNonNull(type, "type"); 041 } 042 043 /** 044 * Returns the error type. 045 */ 046 public String getType() { 047 return type; 048 } 049 050 /** 051 * Returns the ACME error type. This is the last part of the type URN, e.g. 052 * {@code "malformed"} on {@code "urn:ietf:params:acme:error:malformed"}. 053 * 054 * @return ACME error type, or {@code null} if this is not an 055 * {@code "urn:ietf:params:acme:error"} 056 */ 057 public String getAcmeErrorType() { 058 return AcmeUtils.stripErrorPrefix(type); 059 } 060 061}