Skip to content

Commit 9e37ab9

Browse files
committed
feat: handle error messages from login app
1 parent 3709c09 commit 9e37ab9

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/Packages/Passport/Runtime/Scripts/Private/UI/IPassportWebView.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ public class VuplexMessage
1212
public string method;
1313
public string data;
1414
}
15+
16+
/// <summary>
17+
/// Error data structure for JavaScript error messages
18+
/// Matches the TypeScript Error serialization: {message: string, name: string}
19+
/// </summary>
20+
[System.Serializable]
21+
public class ErrorData
22+
{
23+
public string message;
24+
public string name;
25+
26+
public override string ToString()
27+
{
28+
return $"ErrorData(name: {name}, message: {message})";
29+
}
30+
}
1531
/// <summary>
1632
/// Platform abstraction interface for PassportUI WebView implementations.
1733
/// Provides a unified API for different WebView technologies across platforms:

src/Packages/Passport/Runtime/Scripts/Public/PassportUI.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ private void CreateWebView()
197197

198198
// Register JavaScript methods
199199
webView.RegisterJavaScriptMethod("HandleLoginData", HandleLoginData);
200+
webView.RegisterJavaScriptMethod("HandleLoginError", HandleLoginError);
200201

201202
isInitialized = true;
202203
PassportLogger.Info($"{TAG} Cross-platform WebView created successfully");
@@ -369,6 +370,44 @@ private async void HandleLoginData(string jsonData)
369370
}
370371
}
371372

373+
/// <summary>
374+
/// Handles error messages received from JavaScript
375+
/// Called when the login page encounters an error and sends error information
376+
/// </summary>
377+
/// <param name="jsonData">JSON string containing error data</param>
378+
private void HandleLoginError(string jsonData)
379+
{
380+
try
381+
{
382+
PassportLogger.Info($"{TAG} Received error data from JavaScript: {jsonData}");
383+
384+
// Parse the JSON error data
385+
ErrorData errorData = JsonUtility.FromJson<ErrorData>(jsonData);
386+
PassportLogger.Error($"{TAG} Login page error: {errorData}");
387+
388+
// Create user-friendly error message
389+
string errorMessage = !string.IsNullOrEmpty(errorData.message)
390+
? $"Login failed: {errorData.message}"
391+
: "Login failed due to an unknown error";
392+
393+
// Trigger failure events
394+
OnLoginFailure?.Invoke(errorMessage);
395+
OnLoginFailureStatic?.Invoke(errorMessage);
396+
397+
// Hide the WebView after error
398+
HideLoginUI();
399+
}
400+
catch (Exception ex)
401+
{
402+
string errorMessage = $"Failed to handle error message from JavaScript: {ex.Message}";
403+
PassportLogger.Error($"{TAG} {errorMessage}");
404+
405+
// Trigger failure events even if we can't parse the error
406+
OnLoginFailure?.Invoke("Login failed due to an error processing error message");
407+
OnLoginFailureStatic?.Invoke("Login failed due to an error processing error message");
408+
}
409+
}
410+
372411
private void SetupLoginButton()
373412
{
374413
if (loginButton != null)

0 commit comments

Comments
 (0)