Skip to content

Commit

Permalink
Handle bad response from Flickr properly
Browse files Browse the repository at this point in the history
When Flickr gives a bad response back to Scribe (503 error etc) handle
this and throw a FlickrException with error code "105" (the standard
Flickr error code for "Service currently unavailable").
  • Loading branch information
boncey committed Feb 23, 2019
1 parent 2ad76c0 commit a0b5663
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/java/com/flickr4java/flickr/REST.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class REST extends Transport {

private static final String PATH = "/services/rest/";

/**
* Error code from Flickr API when the service is unavailable.
*/
private static final String FLICKR_SERVICE_UNAVAILABLE = "105";

private boolean proxyAuth = false;

private String proxyUser = "";
Expand Down Expand Up @@ -126,7 +131,7 @@ public void setProxy(String proxyHost, int proxyPort, String username, String pa
* @return The Response
*/
@Override
public com.flickr4java.flickr.Response get(String path, Map<String, Object> parameters, String apiKey, String sharedSecret) {
public com.flickr4java.flickr.Response get(String path, Map<String, Object> parameters, String apiKey, String sharedSecret) throws FlickrException {

OAuthRequest request = new OAuthRequest(Verb.GET, buildUrl(path));
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
Expand Down Expand Up @@ -170,7 +175,7 @@ public com.flickr4java.flickr.Response get(String path, Map<String, Object> para
* @return The Response object
*/
@Override
public com.flickr4java.flickr.Response post(String path, Map<String, Object> parameters, String apiKey, String sharedSecret) {
public com.flickr4java.flickr.Response post(String path, Map<String, Object> parameters, String apiKey, String sharedSecret) throws FlickrException {

OAuthRequest request = new OAuthRequest(Verb.POST, buildUrl(path));

Expand All @@ -194,7 +199,7 @@ public com.flickr4java.flickr.Response post(String path, Map<String, Object> par
* @return The Response object
*/
@Override
public com.flickr4java.flickr.Response postMultiPart(String path, UploadMetaData metaData, Payload payload, String apiKey, String sharedSecret) {
public com.flickr4java.flickr.Response postMultiPart(String path, UploadMetaData metaData, Payload payload, String apiKey, String sharedSecret) throws FlickrException {

OAuthRequest request = new OAuthRequest(Verb.POST, buildUrl(path));
Map<String, String> uploadParameters = new HashMap<>(metaData.getUploadParameters());
Expand Down Expand Up @@ -241,9 +246,12 @@ private String buildUrl(String path) {
return String.format("%s://%s%s", getScheme(), getHost(), path);
}

private Response handleResponse(OAuthRequest request, OAuth10aService service) throws InterruptedException, ExecutionException, IOException, SAXException, InstantiationException, IllegalAccessException, ParserConfigurationException {
private Response handleResponse(OAuthRequest request, OAuth10aService service) throws InterruptedException, ExecutionException, IOException, SAXException, InstantiationException, IllegalAccessException, ParserConfigurationException, FlickrException {
com.github.scribejava.core.model.Response scribeResponse = service.execute(request);

if (!scribeResponse.isSuccessful()) {
throw new FlickrException(FLICKR_SERVICE_UNAVAILABLE, String.format("Received '%s' error from Flickr with status %d", scribeResponse.getMessage(), scribeResponse.getCode()));
}
Response f4jResponse;
String strXml = scribeResponse.getBody().trim();
if (Flickr.debugStream) {
Expand Down

0 comments on commit a0b5663

Please sign in to comment.