Skip to content

Commit

Permalink
add exception type and documentation for when rate limiting exception
Browse files Browse the repository at this point in the history
(but not any tests, because that is kind of hard to test without possibly causing a DOS)
  • Loading branch information
westnordost committed Nov 24, 2023
1 parent d1ad890 commit 79cacb9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@

import java.net.HttpURLConnection;

import de.westnordost.osmapi.common.errors.OsmApiException;
import de.westnordost.osmapi.common.errors.OsmAuthorizationException;
import de.westnordost.osmapi.common.errors.OsmBadUserInputException;
import de.westnordost.osmapi.common.errors.OsmConflictException;
import de.westnordost.osmapi.common.errors.OsmConnectionException;
import de.westnordost.osmapi.common.errors.OsmNotFoundException;
import de.westnordost.osmapi.common.errors.OsmPreconditionFailedException;
import de.westnordost.osmapi.common.errors.OsmServiceUnavailableException;
import de.westnordost.osmapi.common.errors.*;

/** Static factory that creates the OsmApiExceptions from the HTTP response code and message */
public class OsmApiErrorFactory
Expand Down Expand Up @@ -38,6 +31,8 @@ public static RuntimeException createError(int error, String response, String de
return new OsmConflictException(error, response, description);
case HttpURLConnection.HTTP_BAD_REQUEST:
return new OsmBadUserInputException(error, response, description);
case 429:
return new OsmTooManyRequestsException(error, response, description);

default:
return createGenericError(error, response, description);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.westnordost.osmapi.common.errors;

/** When the request has been blocked due to rate limiting */
public class OsmTooManyRequestsException extends OsmApiException {
private static final long serialVersionUID = 1L;

public OsmTooManyRequestsException(int errorCode, String errorTitle, String description)
{
super(errorCode, errorTitle, description);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public long updateMap(Map<String, String> tags, Iterable<Element> elements,
* map (Permission.MODIFY_MAP)
* @throws OsmPreconditionFailedException if the deletion of an element was uploaded but that
* element is still referred to by another element
* @throws OsmTooManyRequestsException if the request has been blocked due to rate limiting
* */
public void uploadChanges(long changesetId, Iterable<Element> elements, Handler<DiffElement> handler)
{
Expand Down

0 comments on commit 79cacb9

Please sign in to comment.