Package org.openstreetmap.josm.tools
Class ExceptionUtil
- java.lang.Object
-
- org.openstreetmap.josm.tools.ExceptionUtil
-
public final class ExceptionUtil extends java.lang.Object
Utilities for exception handling.- Since:
- 2097
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<java.lang.String>
OSM_API_BLOCK_MESSAGES
Error messages sent by the OSM API when a user has been blocked/suspended.
-
Constructor Summary
Constructors Modifier Constructor Description private
ExceptionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
explainBadRequest(OsmApiException e)
Explains aOsmApiException
which was thrown because of a bad request.static java.lang.String
explainBandwidthLimitExceeded(OsmApiException e)
Explains aOsmApiException
which was thrown because of bandwidth limit exceeded (HTTP error 509)static java.lang.String
explainChangesetClosedException(ChangesetClosedException e)
Explains an exception thrown during upload because the changeset which data is uploaded to is already closed.static java.lang.String
explainClientTimeout(OsmApiException e)
Explains an OSM API exception because of a client timeout (HTTP 408).static java.lang.String
explainConflict(OsmApiException e)
Explains an error due to a 409 conflictstatic java.lang.String
explainException(java.lang.Exception e)
Explains anException
to the user.static java.lang.String
explainFailedAuthorisation(OsmApiException e)
Explains aOsmApiException
which was thrown because accessing a protected resource was forbidden (HTTP 403), without OAuth authentication.static java.lang.String
explainFailedBasicAuthentication(OsmApiException e)
Explains aOsmApiException
which was thrown because the authentication at the OSM server failed, with basic authentication.static java.lang.String
explainFailedOAuthAuthentication(OsmApiException e)
Explains aOsmApiException
which was thrown because the authentication at the OSM server failed, with OAuth authentication.static java.lang.String
explainFailedOAuthAuthorisation(OsmApiException e)
Explains aOsmApiException
which was thrown because accessing a protected resource was forbidden (HTTP 403), with OAuth authentication.static java.lang.String
explainGeneric(java.lang.Exception e)
Explains an exception with a generic message dialogstatic java.lang.String
explainGenericOsmApiException(OsmApiException e)
Replies a generic error message for an OSM API exceptionstatic java.lang.String
explainGoneForUnknownPrimitive(OsmApiException e)
explains the case of an error due to a delete request on an already deletedOsmPrimitive
, i.e.static java.lang.String
explainInternalServerError(OsmTransferException e)
Explains aOsmApiException
which was thrown because of an internal server error in the OSM API server.static java.lang.String
explainMissingOAuthAccessTokenException(MissingOAuthAccessTokenException e)
Explains aOsmApiException
which was thrown because accessing a protected resource was forbidden.static java.lang.String
explainNestedIllegalDataException(OsmTransferException e)
Explains aIllegalDataException
which has caused anOsmTransferException
.static java.lang.String
explainNestedIOException(OsmTransferException e)
Explains aIOException
which has caused anOsmTransferException
.static java.lang.String
explainNestedSocketException(OsmTransferException e)
Explains aSocketException
which has caused anOsmTransferException
.static java.lang.String
explainNestedUnknownHostException(OsmTransferException e)
Explains aUnknownHostException
which has caused anOsmTransferException
.static java.lang.String
explainNotFound(OsmApiException e)
Explains aOsmApiException
which was thrown because a resource wasn't found.static java.lang.String
explainOfflineAccessException(OsmTransferException e)
Explains aOfflineAccessException
which has caused anOsmTransferException
.static java.lang.String
explainOsmApiInitializationException(OsmApiInitializationException e)
Explains an exception caught during OSM API initialization.static java.lang.String
explainOsmTransferException(OsmTransferException e)
Explains anOsmTransferException
to the user.static java.lang.String
explainPreconditionFailed(OsmApiException e)
Explains an upload error due to a violated precondition, i.e.static java.lang.String
explainSecurityException(OsmTransferException e)
Explains aSecurityException
which has caused anOsmTransferException
.private static java.lang.String
formatClosedOn(java.time.Instant closedOn)
static <T> T
getNestedException(java.lang.Exception e, java.lang.Class<T> nestedClass)
Replies the first nested exception of typenestedClass
(including the root exceptione
) or null, if no such exception is found.(package private) static java.lang.String
getUrlFromException(OsmApiException e)
static boolean
isUserBlocked(OsmApiException e)
Determines if the OSM API exception has been thrown because user has been blocked or suspended.static Pair<OsmPrimitive,java.util.Collection<OsmPrimitive>>
parsePreconditionFailed(java.lang.String msg)
Parses a precondition failure response from the server and attempts to get more information about it
-
-
-
Field Detail
-
OSM_API_BLOCK_MESSAGES
private static final java.util.List<java.lang.String> OSM_API_BLOCK_MESSAGES
Error messages sent by the OSM API when a user has been blocked/suspended.
-
-
Constructor Detail
-
ExceptionUtil
private ExceptionUtil()
-
-
Method Detail
-
explainOsmApiInitializationException
public static java.lang.String explainOsmApiInitializationException(OsmApiInitializationException e)
Explains an exception caught during OSM API initialization.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainMissingOAuthAccessTokenException
public static java.lang.String explainMissingOAuthAccessTokenException(MissingOAuthAccessTokenException e)
Explains aOsmApiException
which was thrown because accessing a protected resource was forbidden.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
parsePreconditionFailed
public static Pair<OsmPrimitive,java.util.Collection<OsmPrimitive>> parsePreconditionFailed(java.lang.String msg)
Parses a precondition failure response from the server and attempts to get more information about it- Parameters:
msg
- The message from the server- Returns:
- The OSM primitive that caused the problem and a collection of primitives that e.g. refer to it
-
explainPreconditionFailed
public static java.lang.String explainPreconditionFailed(OsmApiException e)
Explains an upload error due to a violated precondition, i.e. a HTTP return code 412- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainFailedBasicAuthentication
public static java.lang.String explainFailedBasicAuthentication(OsmApiException e)
Explains aOsmApiException
which was thrown because the authentication at the OSM server failed, with basic authentication.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainFailedOAuthAuthentication
public static java.lang.String explainFailedOAuthAuthentication(OsmApiException e)
Explains aOsmApiException
which was thrown because the authentication at the OSM server failed, with OAuth authentication.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainFailedAuthorisation
public static java.lang.String explainFailedAuthorisation(OsmApiException e)
Explains aOsmApiException
which was thrown because accessing a protected resource was forbidden (HTTP 403), without OAuth authentication.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainFailedOAuthAuthorisation
public static java.lang.String explainFailedOAuthAuthorisation(OsmApiException e)
Explains aOsmApiException
which was thrown because accessing a protected resource was forbidden (HTTP 403), with OAuth authentication.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainClientTimeout
public static java.lang.String explainClientTimeout(OsmApiException e)
Explains an OSM API exception because of a client timeout (HTTP 408).- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainGenericOsmApiException
public static java.lang.String explainGenericOsmApiException(OsmApiException e)
Replies a generic error message for an OSM API exception- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainConflict
public static java.lang.String explainConflict(OsmApiException e)
Explains an error due to a 409 conflict- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainChangesetClosedException
public static java.lang.String explainChangesetClosedException(ChangesetClosedException e)
Explains an exception thrown during upload because the changeset which data is uploaded to is already closed.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
formatClosedOn
private static java.lang.String formatClosedOn(java.time.Instant closedOn)
-
explainGeneric
public static java.lang.String explainGeneric(java.lang.Exception e)
Explains an exception with a generic message dialog- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainSecurityException
public static java.lang.String explainSecurityException(OsmTransferException e)
Explains aSecurityException
which has caused anOsmTransferException
. This is most likely happening when user tries to access the OSM API from within an applet which wasn't loaded from the API server.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainNestedSocketException
public static java.lang.String explainNestedSocketException(OsmTransferException e)
Explains aSocketException
which has caused anOsmTransferException
. This is most likely because there's not connection to the Internet or because the remote server is not reachable.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainNestedIOException
public static java.lang.String explainNestedIOException(OsmTransferException e)
Explains aIOException
which has caused anOsmTransferException
. This is most likely happening when the communication with the remote server is interrupted for any reason.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainNestedIllegalDataException
public static java.lang.String explainNestedIllegalDataException(OsmTransferException e)
Explains aIllegalDataException
which has caused anOsmTransferException
. This is most likely happening when JOSM tries to load data in an unsupported format.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainOfflineAccessException
public static java.lang.String explainOfflineAccessException(OsmTransferException e)
Explains aOfflineAccessException
which has caused anOsmTransferException
. This is most likely happening when JOSM tries to access OSM API or JOSM website while in offline mode.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
- Since:
- 7434
-
explainInternalServerError
public static java.lang.String explainInternalServerError(OsmTransferException e)
Explains aOsmApiException
which was thrown because of an internal server error in the OSM API server.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainBadRequest
public static java.lang.String explainBadRequest(OsmApiException e)
Explains aOsmApiException
which was thrown because of a bad request.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainBandwidthLimitExceeded
public static java.lang.String explainBandwidthLimitExceeded(OsmApiException e)
Explains aOsmApiException
which was thrown because of bandwidth limit exceeded (HTTP error 509)- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainNotFound
public static java.lang.String explainNotFound(OsmApiException e)
Explains aOsmApiException
which was thrown because a resource wasn't found.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainNestedUnknownHostException
public static java.lang.String explainNestedUnknownHostException(OsmTransferException e)
Explains aUnknownHostException
which has caused anOsmTransferException
. This is most likely happening when there is an error in the API URL or when local DNS services are not working.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
getNestedException
public static <T> T getNestedException(java.lang.Exception e, java.lang.Class<T> nestedClass)
Replies the first nested exception of typenestedClass
(including the root exceptione
) or null, if no such exception is found.- Type Parameters:
T
- nested exception type- Parameters:
e
- the root exceptionnestedClass
- the type of the nested exception- Returns:
- the first nested exception of type
nestedClass
(including the root exceptione
) or null, if no such exception is found. - Since:
- 8470
-
explainOsmTransferException
public static java.lang.String explainOsmTransferException(OsmTransferException e)
Explains anOsmTransferException
to the user.- Parameters:
e
- theOsmTransferException
- Returns:
- The HTML formatted error message to display
-
explainGoneForUnknownPrimitive
public static java.lang.String explainGoneForUnknownPrimitive(OsmApiException e)
explains the case of an error due to a delete request on an already deletedOsmPrimitive
, i.e. a HTTP response code 410, where we don't know whichOsmPrimitive
is causing the error.- Parameters:
e
- the exception- Returns:
- The HTML formatted error message to display
-
explainException
public static java.lang.String explainException(java.lang.Exception e)
Explains anException
to the user.- Parameters:
e
- theException
- Returns:
- The HTML formatted error message to display
-
isUserBlocked
public static boolean isUserBlocked(OsmApiException e)
Determines if the OSM API exception has been thrown because user has been blocked or suspended.- Parameters:
e
- OSM API exception- Returns:
true
if the OSM API exception has been thrown because user has been blocked or suspended- Since:
- 15084
-
getUrlFromException
static java.lang.String getUrlFromException(OsmApiException e)
-
-