mirror of https://github.com/shred/acme4j
Accept null for JSON problem type and detail
parent
749abc8f99
commit
6f122e63f1
|
@ -332,6 +332,14 @@ public class DefaultConnection implements Connection {
|
||||||
String type = (String) map.get("type");
|
String type = (String) map.get("type");
|
||||||
String detail = (String) map.get("detail");
|
String detail = (String) map.get("detail");
|
||||||
|
|
||||||
|
if (detail == null) {
|
||||||
|
detail = "general problem";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == null) {
|
||||||
|
throw new AcmeException(detail);
|
||||||
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "urn:acme:error:unauthorized":
|
case "urn:acme:error:unauthorized":
|
||||||
throw new AcmeUnauthorizedException(type, detail);
|
throw new AcmeUnauthorizedException(type, detail);
|
||||||
|
|
|
@ -249,6 +249,31 @@ public class DefaultConnectionTest {
|
||||||
verifyNoMoreInteractions(mockUrlConnection);
|
verifyNoMoreInteractions(mockUrlConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if an {@link AcmeException} is thrown if there is no error type.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testNoTypeThrowException() {
|
||||||
|
when(mockUrlConnection.getHeaderField("Content-Type"))
|
||||||
|
.thenReturn("application/problem+json");
|
||||||
|
|
||||||
|
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection) {
|
||||||
|
@Override
|
||||||
|
public Map<String,Object> readJsonResponse() throws AcmeException {
|
||||||
|
return new HashMap<String, Object>();
|
||||||
|
};
|
||||||
|
}) {
|
||||||
|
conn.conn = mockUrlConnection;
|
||||||
|
conn.throwAcmeException();
|
||||||
|
fail("Expected to fail");
|
||||||
|
} catch (AcmeException ex) {
|
||||||
|
assertThat(ex.getMessage(), not(isEmptyOrNullString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(mockUrlConnection).getHeaderField("Content-Type");
|
||||||
|
verifyNoMoreInteractions(mockUrlConnection);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test GET requests.
|
* Test GET requests.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue