Package net.dv8tion.jda.api.exceptions
Class ErrorResponseException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- net.dv8tion.jda.api.exceptions.ErrorResponseException
-
- All Implemented Interfaces:
java.io.Serializable
public class ErrorResponseException extends java.lang.RuntimeExceptionIndicates an unhandled error that is returned by Discord API Request usingRestAction
It holds anErrorResponse- See Also:
ErrorHandler, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classErrorResponseException.ErrorCodeAn error for aErrorResponseException.SchemaError.static classErrorResponseException.SchemaErrorSchema error which supplies more context to a ErrorResponse.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ErrorResponseExceptioncreate(ErrorResponse errorResponse, Response response)intgetErrorCode()The discord error code for this error response.ErrorResponsegetErrorResponse()TheErrorResponsecorresponding for the received error response from Discordjava.lang.StringgetMeaning()The meaning for this error.ResponsegetResponse()The Discord Response causing the ErrorResponsejava.util.List<ErrorResponseException.SchemaError>getSchemaErrors()TheSchemaErrorsfor this error response.static java.util.function.Consumer<java.lang.Throwable>ignore(java.util.Collection<ErrorResponse> set)Ignore the specified set of error responses.static java.util.function.Consumer<java.lang.Throwable>ignore(java.util.function.Consumer<? super java.lang.Throwable> orElse, java.util.Collection<ErrorResponse> set)Ignore the specified set of error responses.static java.util.function.Consumer<java.lang.Throwable>ignore(java.util.function.Consumer<? super java.lang.Throwable> orElse, ErrorResponse ignored, ErrorResponse... errorResponses)Ignore the specified set of error responses.static java.util.function.Consumer<java.lang.Throwable>ignore(ErrorResponse ignored, ErrorResponse... errorResponses)Ignore the specified set of error responses.booleanisServerError()Whether this is an internal server error from discord (status 500)
-
-
-
Method Detail
-
isServerError
public boolean isServerError()
Whether this is an internal server error from discord (status 500)- Returns:
- True, if this is an internal server error
ErrorResponse.SERVER_ERROR
-
getMeaning
public java.lang.String getMeaning()
The meaning for this error.
It is possible that the value from this method is different forserver errors- Returns:
- Never-null meaning of this error.
-
getErrorCode
public int getErrorCode()
The discord error code for this error response.- Returns:
- The discord error code.
- See Also:
- Discord Error Codes
-
getErrorResponse
public ErrorResponse getErrorResponse()
TheErrorResponsecorresponding for the received error response from Discord- Returns:
ErrorResponse
-
getResponse
public Response getResponse()
The Discord Response causing the ErrorResponse- Returns:
Response
-
getSchemaErrors
@Nonnull public java.util.List<ErrorResponseException.SchemaError> getSchemaErrors()
TheSchemaErrorsfor this error response.
These errors provide more context of what part in the body caused the error, and more explanation for the error itself.- Returns:
- Possibly-empty list of
SchemaError
-
create
public static ErrorResponseException create(ErrorResponse errorResponse, Response response)
-
ignore
@Nonnull public static java.util.function.Consumer<java.lang.Throwable> ignore(@Nonnull java.util.Collection<ErrorResponse> set)Ignore the specified set of error responses.Example
// Creates a message with the provided content and deletes it 30 seconds later public static void selfDestruct(MessageChannel channel, String content) { channel.sendMessage(content).queue((message) -> message.delete().queueAfter(30, SECONDS, null, ignore(EnumSet.of(UNKNOWN_MESSAGE))) ); }- Parameters:
set- Set of ignored error responses- Returns:
Consumerdecorator forRestAction.getDefaultFailure()which ignores the specifiedErrorResponses- Throws:
java.lang.IllegalArgumentException- If provided with null or an empty collection
-
ignore
@Nonnull public static java.util.function.Consumer<java.lang.Throwable> ignore(@Nonnull ErrorResponse ignored, @Nonnull ErrorResponse... errorResponses)Ignore the specified set of error responses.Example
// Creates a message with the provided content and deletes it 30 seconds later public static void selfDestruct(MessageChannel channel, String content) { channel.sendMessage(content).queue((message) -> message.delete().queueAfter(30, SECONDS, null, ignore(UNKNOWN_MESSAGE)) ); }- Parameters:
ignored- Ignored error responseerrorResponses- Additional error responses to ignore- Returns:
Consumerdecorator forRestAction.getDefaultFailure()which ignores the specifiedErrorResponses- Throws:
java.lang.IllegalArgumentException- If provided with null
-
ignore
@Nonnull public static java.util.function.Consumer<java.lang.Throwable> ignore(@Nonnull java.util.function.Consumer<? super java.lang.Throwable> orElse, @Nonnull ErrorResponse ignored, @Nonnull ErrorResponse... errorResponses)Ignore the specified set of error responses.Example
// Creates a message with the provided content and deletes it 30 seconds later public static void selfDestruct(MessageChannel channel, String content) { channel.sendMessage(content).queue((message) -> message.delete().queueAfter(30, SECONDS, null, ignore(Throwable::printStackTrace, UNKNOWN_MESSAGE)) ); }- Parameters:
orElse- Behavior to default to if the error response is not ignoredignored- Ignored error responseerrorResponses- Additional error responses to ignore- Returns:
Consumerdecorator for the provided callback which ignores the specifiedErrorResponses- Throws:
java.lang.IllegalArgumentException- If provided with null
-
ignore
@Nonnull public static java.util.function.Consumer<java.lang.Throwable> ignore(@Nonnull java.util.function.Consumer<? super java.lang.Throwable> orElse, @Nonnull java.util.Collection<ErrorResponse> set)Ignore the specified set of error responses.Example
// Creates a message with the provided content and deletes it 30 seconds later public static void selfDestruct(MessageChannel channel, String content) { channel.sendMessage(content).queue((message) -> message.delete().queueAfter(30, SECONDS, null, ignore(Throwable::printStackTrace, EnumSet.of(UNKNOWN_MESSAGE))) ); }- Parameters:
orElse- Behavior to default to if the error response is not ignoredset- Set of ignored error responses- Returns:
Consumerdecorator for the provided callback which ignores the specifiedErrorResponses- Throws:
java.lang.IllegalArgumentException- If provided with null or an empty collection
-
-