Skip to content

Commit 5dd874f

Browse files
committed
fix the merge conflicts
1 parent c487898 commit 5dd874f

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

src/Core/src/Handlers/HybridWebView/HybridWebView.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,40 @@
7474
const json = JSON.stringify(result);
7575
sendMessageToDotNet('__InvokeJavaScriptCompleted', taskId + '|' + json);
7676
}
77+
/*
78+
* Send a message to the .NET host application indicating that a JavaScript method invocation failed.
79+
* The error message is sent as a string with the following format: `<taskId>|<JSInvokeError>`.
80+
*/
81+
function invokeJavaScriptFailedInDotNet(taskId, error) {
82+
let errorObj;
83+
if (!error) {
84+
errorObj = {
85+
Message: 'Unknown error',
86+
StackTrace: Error().stack
87+
};
88+
}
89+
else if (error instanceof Error) {
90+
errorObj = {
91+
Name: error.name,
92+
Message: error.message,
93+
StackTrace: error.stack
94+
};
95+
}
96+
else if (typeof error === 'string') {
97+
errorObj = {
98+
Message: error,
99+
StackTrace: Error().stack
100+
};
101+
}
102+
else {
103+
errorObj = {
104+
Message: JSON.stringify(error),
105+
StackTrace: Error().stack
106+
};
107+
}
108+
const json = JSON.stringify(errorObj);
109+
sendMessageToDotNet('__InvokeJavaScriptFailed', taskId + '|' + json);
110+
}
77111
const HybridWebView = {
78112
/*
79113
* Send a raw message to the .NET host application.
@@ -143,6 +177,7 @@
143177
}
144178
catch (ex) {
145179
console.error(ex);
180+
invokeJavaScriptFailedInDotNet(taskId, ex);
146181
}
147182
}
148183
};

src/Core/src/Handlers/HybridWebView/HybridWebView.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ interface DotNetInvokeResult {
5555
(() => {
5656

5757
// Cached function to send messages to the host application.
58-
let sendMessageFunction: (message: any) => void = null;
58+
let sendMessageFunction: ((message: any) => void) | null = null;
5959

6060
/*
6161
* Initialize the HybridWebView messaging system.
@@ -125,6 +125,41 @@ interface DotNetInvokeResult {
125125
sendMessageToDotNet('__InvokeJavaScriptCompleted', taskId + '|' + json);
126126
}
127127

128+
/*
129+
* Send a message to the .NET host application indicating that a JavaScript method invocation failed.
130+
* The error message is sent as a string with the following format: `<taskId>|<JSInvokeError>`.
131+
*/
132+
function invokeJavaScriptFailedInDotNet(taskId: string, error: any) {
133+
let errorObj: JSInvokeError;
134+
135+
if (!error) {
136+
errorObj = {
137+
Message: 'Unknown error',
138+
StackTrace: Error().stack
139+
};
140+
} else if (error instanceof Error) {
141+
errorObj = {
142+
Name: error.name,
143+
Message: error.message,
144+
StackTrace: error.stack
145+
};
146+
} else if (typeof error === 'string') {
147+
errorObj = {
148+
Message: error,
149+
StackTrace: Error().stack
150+
};
151+
} else {
152+
errorObj = {
153+
Message: JSON.stringify(error),
154+
StackTrace: Error().stack
155+
};
156+
}
157+
158+
const json = JSON.stringify(errorObj);
159+
160+
sendMessageToDotNet('__InvokeJavaScriptFailed', taskId + '|' + json);
161+
}
162+
128163
const HybridWebView = {
129164

130165
/*
@@ -205,6 +240,7 @@ interface DotNetInvokeResult {
205240
invokeJavaScriptCallbackInDotNet(taskId, result);
206241
} catch (ex) {
207242
console.error(ex);
243+
invokeJavaScriptFailedInDotNet(taskId, ex);
208244
}
209245
}
210246
};

0 commit comments

Comments
 (0)