@robotical/webapp-types 3.23.2 → 3.23.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-types/package.json
CHANGED
|
@@ -44,6 +44,39 @@ import { addRobotNameToSerialNumber, isSerialNumberRegistered } from "../../util
|
|
|
44
44
|
import { buildAnalyticsDeviceInfo } from "../../utils/analytics-device-info";
|
|
45
45
|
var SHOW_LOGS = true;
|
|
46
46
|
var TAG = "RAFT";
|
|
47
|
+
var getBridgeResultType = function (result) {
|
|
48
|
+
if (result === null)
|
|
49
|
+
return "null";
|
|
50
|
+
if (Array.isArray(result))
|
|
51
|
+
return "array";
|
|
52
|
+
return typeof result;
|
|
53
|
+
};
|
|
54
|
+
var getBridgeErrorMessage = function (result) {
|
|
55
|
+
if (result instanceof Error && result.message.trim()) {
|
|
56
|
+
return result.message;
|
|
57
|
+
}
|
|
58
|
+
if (typeof result === "string" && result.trim()) {
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
if (result && typeof result === "object" && "error" in result) {
|
|
62
|
+
var error = result.error;
|
|
63
|
+
if (typeof error === "string" && error.trim()) {
|
|
64
|
+
return error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
};
|
|
69
|
+
var createConnectionBridgeError = function (result, method) {
|
|
70
|
+
var error = new Error(getBridgeErrorMessage(result) ||
|
|
71
|
+
"The connection bridge did not return a valid result.");
|
|
72
|
+
error.connectionContext = {
|
|
73
|
+
phase: "connect",
|
|
74
|
+
method: method,
|
|
75
|
+
bridgeMessage: AppSentMessage.RAFT_CONNECT,
|
|
76
|
+
bridgeResultType: getBridgeResultType(result),
|
|
77
|
+
};
|
|
78
|
+
return error;
|
|
79
|
+
};
|
|
47
80
|
var RAFT = /** @class */ (function () {
|
|
48
81
|
function RAFT(id) {
|
|
49
82
|
this.id = id;
|
|
@@ -119,8 +152,9 @@ var RAFT = /** @class */ (function () {
|
|
|
119
152
|
connectResults = _a.sent();
|
|
120
153
|
if (!connectResults ||
|
|
121
154
|
typeof connectResults !== "object" ||
|
|
155
|
+
!("success" in connectResults) ||
|
|
122
156
|
typeof connectResults.success !== "boolean") {
|
|
123
|
-
throw
|
|
157
|
+
throw createConnectionBridgeError(connectResults, method);
|
|
124
158
|
}
|
|
125
159
|
return [2 /*return*/, connectResults];
|
|
126
160
|
}
|
|
@@ -139,15 +139,31 @@ var getLogMessage = function (messages) {
|
|
|
139
139
|
.trim();
|
|
140
140
|
return message || "Unknown error";
|
|
141
141
|
};
|
|
142
|
+
var getConnectionErrorContext = function (error) {
|
|
143
|
+
if (!error || !("connectionContext" in error))
|
|
144
|
+
return null;
|
|
145
|
+
var context = error
|
|
146
|
+
.connectionContext;
|
|
147
|
+
if (!context || typeof context !== "object")
|
|
148
|
+
return null;
|
|
149
|
+
var safeContext = Object.fromEntries(Object.entries(context).filter(function (entry) { return typeof entry[1] === "string"; }));
|
|
150
|
+
return Object.keys(safeContext).length ? safeContext : null;
|
|
151
|
+
};
|
|
142
152
|
export function captureLoggerError(tag, messages) {
|
|
143
153
|
if (!Sentry.isInitialized())
|
|
144
154
|
return;
|
|
145
155
|
try {
|
|
146
156
|
var error_1 = messages.find(function (message) { return message instanceof Error; });
|
|
147
157
|
var message_1 = getLogMessage(messages);
|
|
158
|
+
var connectionContext_1 = getConnectionErrorContext(error_1);
|
|
148
159
|
Sentry.withScope(function (scope) {
|
|
149
160
|
scope.setLevel("error");
|
|
150
161
|
scope.setTag("logger_tag", tag);
|
|
162
|
+
if (connectionContext_1) {
|
|
163
|
+
scope.setTag("connection_phase", connectionContext_1.phase);
|
|
164
|
+
scope.setTag("connection_method", connectionContext_1.method);
|
|
165
|
+
scope.setContext("connection", connectionContext_1);
|
|
166
|
+
}
|
|
151
167
|
scope.setContext("logger", {
|
|
152
168
|
message: message_1,
|
|
153
169
|
arguments: messages,
|