public static RecurlyAPIError buildFromResponse(final Response response) { final RecurlyAPIError recurlyAPIError = new RecurlyAPIError(); recurlyAPIError.setResponse(response); return recurlyAPIError; }
protected void setResponse(final Response response) { this.setHttpStatusCode(response.getStatusCode()); this.setResponseMetadata(new ResponseMetadata(response)); }
log.warn("Recurly error whilst calling: {}\n{}", response.getUri(), payload); log.warn("Error status code: {}\n", response.getStatusCode()); RecurlyAPIError recurlyError = RecurlyAPIError.buildFromResponse(response); recurlyError.setSymbol("unauthorized"); recurlyError.setDescription("We could not authenticate your request. Either your subdomain and private key are not set or incorrect"); recurlyError = RecurlyAPIError.buildFromXml(xmlMapper, payload, response); } catch (Exception e) { log.debug("Unable to extract error", e);
@Test(groups = "integration") public void testUnauthorizedException() throws Exception { final String subdomain = System.getProperty(KILLBILL_PAYMENT_RECURLY_SUBDOMAIN); RecurlyClient unauthorizedRecurlyClient = new RecurlyClient("invalid-api-key", subdomain); unauthorizedRecurlyClient.open(); try { unauthorizedRecurlyClient.getAccounts(); Assert.fail("getAccounts call should not succeed with invalid credentials."); } catch (RecurlyAPIException expected) { Assert.assertEquals(expected.getRecurlyError().getSymbol(), "unauthorized"); } }
Assert.fail("Failed to delete the Adjustment"); } catch (final RecurlyAPIException e) { Assert.assertEquals(e.getRecurlyError().getHttpStatusCode(), 404);
public static RecurlyAPIError buildFromXml(final XmlMapper xmlMapper, final String payload, final Response response) throws IOException { final RecurlyAPIError recurlyAPIError = xmlMapper.readValue(payload, RecurlyAPIError.class); recurlyAPIError.setResponse(response); return recurlyAPIError; }
private InputStream callRecurlySafeGetPdf(String url) { final Response response; final InputStream pdfInputStream; try { response = clientRequestBuilderCommon(client.prepareGet(url)) .addHeader("Accept", "application/pdf") .addHeader("Content-Type", "application/pdf") .execute() .get(); pdfInputStream = response.getResponseBodyAsStream(); } catch (InterruptedException e) { log.error("Interrupted while calling recurly", e); return null; } catch (ExecutionException e) { log.error("Execution error", e); return null; } catch (IOException e) { log.error("Error retrieving response body", e); return null; } if (response.getStatusCode() != 200) { final RecurlyAPIError recurlyAPIError = RecurlyAPIError.buildFromResponse(response); throw new RecurlyAPIException(recurlyAPIError); } return pdfInputStream; }
@Test(groups = "integration") public void testUnauthorizedException() throws Exception { final String subdomain = System.getProperty(KILLBILL_PAYMENT_RECURLY_SUBDOMAIN); RecurlyClient unauthorizedRecurlyClient = new RecurlyClient("invalid-api-key", subdomain); unauthorizedRecurlyClient.open(); try { unauthorizedRecurlyClient.getAccounts(); Assert.fail("getAccounts call should not succeed with invalid credentials."); } catch (RecurlyAPIException expected) { Assert.assertEquals(expected.getRecurlyError().getSymbol(), "unauthorized"); } }
Assert.fail("Failed to delete the Adjustment"); } catch (final RecurlyAPIException e) { Assert.assertEquals(e.getRecurlyError().getHttpStatusCode(), 404);
} catch (RecurlyAPIException ex) { final RecurlyAPIError err = ex.getRecurlyError(); Assert.assertEquals(err.getSymbol(), "not_found"); } catch (Exception ex) { Assert.fail("Fetching deleted shipping address should have failed with 404 and instead failed because: " + ex.getMessage());
} catch (RecurlyAPIException ex) { final RecurlyAPIError err = ex.getRecurlyError(); Assert.assertEquals(err.getSymbol(), "not_found"); } catch (Exception ex) { Assert.fail("Fetching deleted shipping address should have failed with 404 and instead failed because: " + ex.getMessage());