mirror of https://github.com/shred/acme4j
Use constants for acme error prefixes
parent
91c402473f
commit
57194ce0fc
|
@ -56,6 +56,11 @@ import org.slf4j.LoggerFactory;
|
|||
public class DefaultConnection implements Connection {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DefaultConnection.class);
|
||||
|
||||
public static final String ACME_ERROR_PREFIX = "urn:ietf:params:acme:error:";
|
||||
|
||||
@Deprecated
|
||||
public static final String ACME_ERROR_PREFIX_DEPRECATED = "urn:acme:error:";
|
||||
|
||||
private static final Pattern BASE64URL_PATTERN = Pattern.compile("[0-9A-Za-z_-]+");
|
||||
|
||||
protected final HttpConnector httpConnector;
|
||||
|
@ -313,12 +318,12 @@ public class DefaultConnection implements Connection {
|
|||
}
|
||||
|
||||
switch (type) {
|
||||
case "urn:acme:error:unauthorized":
|
||||
case "urn:ietf:params:acme:error:unauthorized":
|
||||
case ACME_ERROR_PREFIX + "unauthorized":
|
||||
case ACME_ERROR_PREFIX_DEPRECATED + "unauthorized":
|
||||
throw new AcmeUnauthorizedException(type, detail);
|
||||
|
||||
case "urn:acme:error:rateLimited":
|
||||
case "urn:ietf:params:acme:error:rateLimited":
|
||||
case ACME_ERROR_PREFIX + "rateLimited":
|
||||
case ACME_ERROR_PREFIX_DEPRECATED + "rateLimited":
|
||||
throw new AcmeRateLimitExceededException(type, detail, getRetryAfterHeader());
|
||||
|
||||
default:
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
*/
|
||||
package org.shredzone.acme4j.exception;
|
||||
|
||||
import org.shredzone.acme4j.connector.DefaultConnection;
|
||||
|
||||
/**
|
||||
* An exception that is thrown when the ACME server returned an error. It contains
|
||||
* further details of the cause.
|
||||
|
@ -20,9 +22,6 @@ package org.shredzone.acme4j.exception;
|
|||
public class AcmeServerException extends AcmeException {
|
||||
private static final long serialVersionUID = 5971622508467042792L;
|
||||
|
||||
private static final String ACME_ERROR_PREFIX = "urn:ietf:params:acme:error:";
|
||||
private static final String ACME_ERROR_PREFIX_DEPRECATED = "urn:acme:error:";
|
||||
|
||||
private final String type;
|
||||
|
||||
/**
|
||||
|
@ -56,11 +55,12 @@ public class AcmeServerException extends AcmeException {
|
|||
* @return ACME error type, or {@code null} if this is not an
|
||||
* {@code "urn:ietf:params:acme:error"}
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public String getAcmeErrorType() {
|
||||
if (type.startsWith(ACME_ERROR_PREFIX)) {
|
||||
return type.substring(ACME_ERROR_PREFIX.length());
|
||||
} else if (type.startsWith(ACME_ERROR_PREFIX_DEPRECATED)) {
|
||||
return type.substring(ACME_ERROR_PREFIX_DEPRECATED.length());
|
||||
if (type.startsWith(DefaultConnection.ACME_ERROR_PREFIX)) {
|
||||
return type.substring(DefaultConnection.ACME_ERROR_PREFIX.length());
|
||||
} else if (type.startsWith(DefaultConnection.ACME_ERROR_PREFIX_DEPRECATED)) {
|
||||
return type.substring(DefaultConnection.ACME_ERROR_PREFIX_DEPRECATED.length());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue