Package discord4j.common.close
Class CloseException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- discord4j.common.close.CloseException
-
- All Implemented Interfaces:
Serializable
public class CloseException extends RuntimeException
Unchecked exception thrown when closing a websocket session, expectedly or not.Used to wrap an underlying websocket
CloseStatusso clients can retrieve the status code and perform actions after it.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CloseException(CloseStatus closeStatus, ContextView context)Create aCloseExceptionwith the given status and Reactor context.CloseException(CloseStatus closeStatus, ContextView context, Throwable cause)Create aCloseExceptionwith the given status, Reactor context and cause.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CloseStatusgetCloseStatus()Return the underlyingCloseStatusthat triggered this exception.intgetCode()Return the websocket close code.ContextViewgetContext()Return the ReactorContextViewproviding metadata about this exception.StringgetMessage()Optional<String>getReason()Return a websocket close reason, if present.-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
CloseException
public CloseException(CloseStatus closeStatus, ContextView context)
Create aCloseExceptionwith the given status and Reactor context.- Parameters:
closeStatus- theCloseStatusrepresenting this exceptioncontext- aContextViewinstance representing metadata related to this exception
-
CloseException
public CloseException(CloseStatus closeStatus, ContextView context, @Nullable Throwable cause)
Create aCloseExceptionwith the given status, Reactor context and cause.- Parameters:
closeStatus- theCloseStatusrepresenting this exceptioncontext- aContextViewinstance providing metadata related to this exceptioncause- the cause for this exception
-
-
Method Detail
-
getCloseStatus
public CloseStatus getCloseStatus()
Return the underlyingCloseStatusthat triggered this exception.- Returns:
- a close status
-
getCode
public int getCode()
Return the websocket close code.- Returns:
- a websocket close code
-
getReason
public Optional<String> getReason()
Return a websocket close reason, if present.- Returns:
- an
Optionalcontaining a close reason if present, or empty otherwise
-
getContext
public ContextView getContext()
Return the ReactorContextViewproviding metadata about this exception.- Returns:
- a Reactor context instance
-
getMessage
public String getMessage()
- Overrides:
getMessagein classThrowable
-
-