1 module hunt.http.codec.websocket.exception; 2 3 import hunt.http.codec.websocket.model.StatusCode; 4 import hunt.lang.exception; 5 6 7 class WebSocketException : RuntimeException 8 { 9 mixin BasicExceptionCtors; 10 } 11 12 class CloseException : WebSocketException 13 { 14 private int statusCode; 15 16 this(int closeCode, string message, size_t line = __LINE__, string file = __FILE__) { 17 super(message); 18 this.statusCode = closeCode; 19 } 20 21 this(int closeCode, string message, Throwable cause, size_t line = __LINE__, string file = __FILE__) { 22 super(message, cause); 23 this.statusCode = closeCode; 24 } 25 26 this(int closeCode, Throwable cause, size_t line = __LINE__, string file = __FILE__) { 27 super(cause); 28 this.statusCode = closeCode; 29 } 30 31 int getStatusCode() { 32 return statusCode; 33 } 34 35 } 36 37 class BadPayloadException : CloseException 38 { 39 this(string message, size_t line = __LINE__, string file = __FILE__) { 40 super(StatusCode.BAD_PAYLOAD, message, line, file); 41 } 42 43 this(string message, Throwable t, size_t line = __LINE__, string file = __FILE__) { 44 super(StatusCode.BAD_PAYLOAD, message, t, line, file); 45 } 46 47 this(Throwable t, size_t line = __LINE__, string file = __FILE__) { 48 super(StatusCode.BAD_PAYLOAD, t, line, file); 49 } 50 } 51 52 class MessageTooLargeException : CloseException 53 { 54 this(string message, size_t line = __LINE__, string file = __FILE__) { 55 super(StatusCode.MESSAGE_TOO_LARGE, message, line, file); 56 } 57 58 this(string message, Throwable t, size_t line = __LINE__, string file = __FILE__) { 59 super(StatusCode.MESSAGE_TOO_LARGE, message, t, line, file); 60 } 61 62 this(Throwable t, size_t line = __LINE__, string file = __FILE__) { 63 super(StatusCode.MESSAGE_TOO_LARGE, t, line, file); 64 } 65 } 66 67 class ProtocolException : CloseException 68 { 69 this(string message, size_t line = __LINE__, string file = __FILE__) { 70 super(StatusCode.PROTOCOL, message, line, file); 71 } 72 73 this(string message, Throwable t, size_t line = __LINE__, string file = __FILE__) { 74 super(StatusCode.PROTOCOL, message, t, line, file); 75 } 76 77 this(Throwable t, size_t line = __LINE__, string file = __FILE__) { 78 super(StatusCode.PROTOCOL, t, line, file); 79 } 80 }