1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135 | package Torello.Browser;
import javax.json.JsonObject;
import java.util.function.Consumer;
// <LI> {@link #closeSocket(WebSocketSender)} — forcibly closes connection
/**
* RDPError represents a fatal or protocol-level error encountered while communicating with
* a Chrome Debugging Protocol WebSocket.
*
* <BR /><BR />
* This class also defines several standard error-handling behaviors (as static constants
* or factories) that may be passed to the {@link WebSocketSender} constructor as a
* {@code Consumer<RDPError>}.
*/
public final class RDPError
{
// ********************************************************************************************
// ********************************************************************************************
// Public, Final Fields
// ********************************************************************************************
// ********************************************************************************************
public final String message;
public final Throwable cause;
public final JsonObject context;
// ********************************************************************************************
// ********************************************************************************************
// Constructor
// ********************************************************************************************
// ********************************************************************************************
RDPError(String message)
{
if (message == null) System.err.println("Input to Error has a null message");
this.message = message;
this.context = null;
this.cause = null;
}
RDPError(final String message, final JsonObject jo)
{
if (message == null)
System.err.println("Input to RDPError Constructor has a null message");
if (jo == null) System.err.println
("Input to RDPError Constructor has a null JsonObject-Parameter");
this.message = message;
this.context = jo;
this.cause = null;
}
RDPError(final String message, final Throwable cause)
{
if (message == null) System.err.println
("Input to RDPError Constructor has a null message");
if (cause == null) System.err.println
("Input to RDPError Constructor has a null Throwable-Parameter");
this.message = message;
this.cause = cause;
this.context = null;
}
RDPError(String message, JsonObject jo, Throwable cause)
{
if (message == null) System.err.println
("Input to RDPError Constructor has a null message");
if (jo == null) System.err.println
("Input to RDPError Constructor has a null JsonObject-Parameter");
if (cause == null) System.err.println
("Input to RDPError Constructor has a null Throwable-Parameter");
this.message = message;
this.context = jo;
this.cause = cause;
}
// ********************************************************************************************
// ********************************************************************************************
// Instance Methods
// ********************************************************************************************
// ********************************************************************************************
@Override
public String toString()
{
return
"{\n" +
message +
((cause != null) ? ("\nCause: " + cause) : "") +
((context != null) ? ("\nJsonObject Context:\n" + context.toString()) : "") +
'}';
}
// ********************************************************************************************
// ********************************************************************************************
// Predefined Error Handlers
// ********************************************************************************************
// ********************************************************************************************
public static final Consumer<RDPError> EXIT_ON_ERROR = (RDPError error) ->
{ System.exit(1); };
public static final Consumer<RDPError> THROW_INTERNAL_ERROR = (RDPError error) ->
{
throw new InternalError
("[RDPError.THROW_INTERNAL_ERROR] " + error.message, error.cause);
};
/*
public static Consumer<RDPError> closeSocket(WebSocketSender sender)
{
return error -> {
System.err.println("[RDPError.closeSocket] " + error);
sender.webSocket().sendClose(1011, "Internal Error");
};
}
*/
public static final Consumer<RDPError> NO_OP = (RDPError error) -> { };
}
|