Class ErrorResponseException

    • 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 String getMeaning()
        The meaning for this error.
        It is possible that the value from this method is different for server 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
      • getResponse

        public Response getResponse()
        The Discord Response causing the ErrorResponse
        Returns:
        Response
      • ignore

        @Nonnull
        public static Consumer<Throwable> ignore​(@Nonnull
                                                 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:
        Consumer decorator for RestAction.getDefaultFailure() which ignores the specified ErrorResponses
        Throws:
        IllegalArgumentException - If provided with null or an empty collection
      • ignore

        @Nonnull
        public static Consumer<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 response
        errorResponses - Additional error responses to ignore
        Returns:
        Consumer decorator for RestAction.getDefaultFailure() which ignores the specified ErrorResponses
        Throws:
        IllegalArgumentException - If provided with null
      • ignore

        @Nonnull
        public static Consumer<Throwable> ignore​(@Nonnull
                                                 Consumer<? super 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 ignored
        ignored - Ignored error response
        errorResponses - Additional error responses to ignore
        Returns:
        Consumer decorator for the provided callback which ignores the specified ErrorResponses
        Throws:
        IllegalArgumentException - If provided with null
      • ignore

        @Nonnull
        public static Consumer<Throwable> ignore​(@Nonnull
                                                 Consumer<? super Throwable> orElse,
                                                 @Nonnull
                                                 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 ignored
        set - Set of ignored error responses
        Returns:
        Consumer decorator for the provided callback which ignores the specified ErrorResponses
        Throws:
        IllegalArgumentException - If provided with null or an empty collection