diff options
author | Fred Quintana <fredq@google.com> | 2009-09-22 18:50:38 -0700 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2009-09-22 18:51:58 -0700 |
commit | f91b52754c8ca935af7d700078de1e6ba2b14ca4 (patch) | |
tree | 97406f250cf5e6eaea3c8c6d06f0729c3b13ae67 | |
parent | 435a35c009070054256eabedb4493b8bc634ebf3 (diff) | |
download | gdata-f91b52754c8ca935af7d700078de1e6ba2b14ca4.tar.gz |
add BadRequestException for when 400 is returned
make the GDataClient throw BadRequestException when a 400 is seen rather than ParseException
-rw-r--r-- | src/com/google/wireless/gdata2/client/BadRequestException.java | 37 | ||||
-rw-r--r-- | src/com/google/wireless/gdata2/client/GDataServiceClient.java | 32 |
2 files changed, 60 insertions, 9 deletions
diff --git a/src/com/google/wireless/gdata2/client/BadRequestException.java b/src/com/google/wireless/gdata2/client/BadRequestException.java new file mode 100644 index 0000000..6e2e98b --- /dev/null +++ b/src/com/google/wireless/gdata2/client/BadRequestException.java @@ -0,0 +1,37 @@ +// Copyright 2009 The Android Open Source Project. + +package com.google.wireless.gdata2.client; + +import com.google.wireless.gdata2.GDataException; + +/** + * Exception thrown when the server returns a 400 Bad Request. + */ +public class BadRequestException extends GDataException { + + /** + * Creates a new AuthenticationException. + */ + public BadRequestException() { + } + + /** + * Creates a new BadRequestException with a supplied message. + * @param message The message for the exception. + */ + public BadRequestException(String message) { + super(message); + } + + /** + * Creates a new BadRequestException with a supplied message and + * underlying cause. + * + * @param message The message for the exception. + * @param cause Another throwable that was caught and wrapped in this + * exception. + */ + public BadRequestException(String message, Throwable cause) { + super(message, cause); + } +}
\ No newline at end of file diff --git a/src/com/google/wireless/gdata2/client/GDataServiceClient.java b/src/com/google/wireless/gdata2/client/GDataServiceClient.java index dfdc31f..5e0aea1 100644 --- a/src/com/google/wireless/gdata2/client/GDataServiceClient.java +++ b/src/com/google/wireless/gdata2/client/GDataServiceClient.java @@ -169,10 +169,12 @@ public abstract class GDataServiceClient { * @throws ParseException Thrown if the server response cannot be parsed. * @throws IOException Thrown if an error occurs while communicating with the * GData service. + * @throws BadRequestException thrown if the server returns a 400 + * @throws ForbiddenException thrown if the server returns a 403 */ public Entry createEntry(String feedUrl, String authToken, Entry entry) throws ConflictDetectedException, AuthenticationException, PreconditionFailedException, - HttpException, ParseException, IOException, ForbiddenException { + HttpException, ParseException, IOException, ForbiddenException, BadRequestException { GDataSerializer serializer = gDataParserFactory.createSerializer(entry); try { InputStream is = @@ -241,10 +243,13 @@ public abstract class GDataServiceClient { * @throws ParseException Thrown if the server response cannot be parsed. * @throws IOException Thrown if an error occurs while communicating with the * GData service. + * @throws BadRequestException thrown if the server returns a 400 + * @throws ForbiddenException thrown if the server returns a 403 + * @throws ResourceNotFoundException Thrown if the resource was not found. */ public Entry updateEntry(Entry entry, String authToken) throws AuthenticationException, ConflictDetectedException, PreconditionFailedException, HttpException, ParseException, - IOException, ForbiddenException, ResourceNotFoundException { + IOException, ForbiddenException, ResourceNotFoundException, BadRequestException { String editUri = entry.getEditUri(); if (StringUtils.isEmpty(editUri)) { throw new ParseException("No edit URI -- cannot update."); @@ -286,11 +291,14 @@ public abstract class GDataServiceClient { * @throws ParseException Thrown if the server response cannot be parsed. * @throws IOException Thrown if an error occurs while communicating with the * GData service. + * @throws BadRequestException thrown if the server returns a 400 + * @throws ForbiddenException thrown if the server returns a 403 + * @throws ResourceNotFoundException Thrown if the resource was not found. */ public MediaEntry updateMediaEntry(String editUri, InputStream inputStream, String contentType, String authToken, String eTag) throws AuthenticationException, ConflictDetectedException, PreconditionFailedException, HttpException, ParseException, IOException, - ForbiddenException, ResourceNotFoundException { + ForbiddenException, ResourceNotFoundException, BadRequestException { if (StringUtils.isEmpty(editUri)) { throw new IllegalArgumentException("No edit URI -- cannot update."); } @@ -323,11 +331,14 @@ public abstract class GDataServiceClient { * @throws ParseException Thrown if the server response cannot be parsed. * @throws IOException Thrown if an error occurs while communicating with the * GData service. + * @throws BadRequestException thrown if the server returns a 400 + * @throws ForbiddenException thrown if the server returns a 403 + * @throws ResourceNotFoundException Thrown if the resource was not found. */ public void deleteEntry(String editUri, String authToken, String eTag) throws AuthenticationException, ConflictDetectedException, PreconditionFailedException, HttpException, ParseException, IOException, ForbiddenException, - ResourceNotFoundException { + ResourceNotFoundException, BadRequestException { try { gDataClient.deleteEntry(editUri, authToken, eTag); } catch (HttpException e) { @@ -365,10 +376,12 @@ public abstract class GDataServiceClient { * @throws ParseException Thrown if the server response cannot be parsed. * @throws IOException Thrown if an error occurs while communicating with the * GData service. + * @throws BadRequestException thrown if the server returns a 400 + * @throws ForbiddenException thrown if the server returns a 403 */ public GDataParser submitBatch(Class feedEntryClass, String batchUrl, String authToken, Enumeration entries) throws AuthenticationException, HttpException, ParseException, - IOException, ForbiddenException { + IOException, ForbiddenException, BadRequestException { GDataSerializer serializer = gDataParserFactory.createSerializer(entries); try { InputStream is = @@ -417,14 +430,15 @@ public abstract class GDataServiceClient { } protected void convertHttpExceptionsForBatches(String message, HttpException cause) - throws AuthenticationException, ParseException, HttpException, ForbiddenException { + throws AuthenticationException, ParseException, HttpException, ForbiddenException, + BadRequestException { switch (cause.getStatusCode()) { case HttpException.SC_FORBIDDEN: throw new ForbiddenException(message, cause); case HttpException.SC_UNAUTHORIZED: throw new AuthenticationException(message, cause); case HttpException.SC_BAD_REQUEST: - throw new ParseException(message + ": " + cause); + throw new BadRequestException(message, cause); default: throw new HttpException(message + ": " + cause.getMessage(), cause.getStatusCode(), cause .getResponseStream()); @@ -435,7 +449,7 @@ public abstract class GDataServiceClient { HttpException cause) throws ConflictDetectedException, AuthenticationException, PreconditionFailedException, ParseException, HttpException, IOException, ForbiddenException, - ResourceNotFoundException { + ResourceNotFoundException, BadRequestException { switch (cause.getStatusCode()) { case HttpException.SC_CONFLICT: Entry entry = null; @@ -447,7 +461,7 @@ public abstract class GDataServiceClient { } throw new ConflictDetectedException(entry); case HttpException.SC_BAD_REQUEST: - throw new ParseException(message + ": " + cause); + throw new BadRequestException(message, cause); case HttpException.SC_FORBIDDEN: throw new ForbiddenException(message, cause); case HttpException.SC_UNAUTHORIZED: |