Verbose exception when getOrders is not supported by the server

pull/89/head
Richard Körber 2020-04-30 19:35:37 +02:00
parent 355a00b293
commit 1eb3965ac0
No known key found for this signature in database
GPG Key ID: AAB9FD19C78AA3E0
1 changed files with 8 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.CheckForNull;
import javax.annotation.ParametersAreNonnullByDefault;
@ -128,8 +129,13 @@ public class Account extends AcmeJsonResource {
* {@link Order} objects in a different order.
*/
public Iterator<Order> getOrders() {
URL ordersUrl = getJSON().get(KEY_ORDERS).asURL();
return new ResourceIterator<>(getLogin(), KEY_ORDERS, ordersUrl, Login::bindOrder);
Optional<URL> ordersUrl = getJSON().get(KEY_ORDERS).optional().map(Value::asURL);
if (!ordersUrl.isPresent()) {
// Let's Encrypt does not provide this field at the moment although it's required.
// See https://github.com/letsencrypt/boulder/issues/3335
throw new AcmeProtocolException("This ACME server does not support getOrders()");
}
return new ResourceIterator<>(getLogin(), KEY_ORDERS, ordersUrl.get(), Login::bindOrder);
}
/**