mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-05-09 07:46:13 -04:00
Add 413 error handling to AliasVault.Client (#1786)
This commit is contained in:
committed by
Leendert de Borst
parent
b40ea721bd
commit
38b0c866a6
@@ -1296,7 +1296,7 @@ else
|
||||
|
||||
if (Id is null || Id == Guid.Empty)
|
||||
{
|
||||
GlobalNotificationService.AddErrorMessage(Localizer["ErrorSavingItem"], true);
|
||||
// Save failed. Stay on the page so the global notification bar can show the error.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -749,11 +749,11 @@
|
||||
{
|
||||
GlobalNotificationService.AddSuccessMessage(string.Format(Localizer["ImportSuccessMessage"], ImportedCredentials.Count));
|
||||
NavigationManager.NavigateTo("/items");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
ImportError = Localizer["ImportErrorGeneric"];
|
||||
}
|
||||
|
||||
// Save failed. Close the import modal and let the user see the error via the global notification bar on the underlying page.
|
||||
CloseModal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -231,6 +231,14 @@
|
||||
<value>An unknown error occurred. Please try again.</value>
|
||||
<comment>Generic unknown error message</comment>
|
||||
</data>
|
||||
<data name="VaultTooLargeError" xml:space="preserve">
|
||||
<value>The vault is too large for the server to accept. Try to remove some items or attachments to reduce the size and try again.</value>
|
||||
<comment>Shown when the server rejects a vault upload with HTTP 413 because the encrypted vault exceeds the configured upload size limit</comment>
|
||||
</data>
|
||||
<data name="VaultSaveError" xml:space="preserve">
|
||||
<value>Failed to save changes to the vault. Please try again.</value>
|
||||
<comment>Generic error shown when a vault save / sync to the server fails for an unexpected reason</comment>
|
||||
</data>
|
||||
<data name="ErrorValidation" xml:space="preserve">
|
||||
<value>Please correct the errors below.</value>
|
||||
<comment>Validation error message</comment>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
namespace AliasVault.Client.Services.Database;
|
||||
|
||||
using System.Data;
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using AliasClientDb;
|
||||
@@ -260,9 +261,8 @@ public sealed class DbService : IDisposable
|
||||
}
|
||||
else
|
||||
{
|
||||
// SaveToServerAsync already raised the user-facing error notification (targeted or generic).
|
||||
_logger.LogWarning("Background sync to server failed.");
|
||||
_globalNotificationService.AddErrorMessage(
|
||||
"Failed to sync changes to server. Your changes are saved locally and will be synced on next refresh.");
|
||||
_state.UpdateState(DbServiceState.DatabaseStatus.Ready);
|
||||
}
|
||||
}
|
||||
@@ -906,6 +906,15 @@ public sealed class DbService : IDisposable
|
||||
{
|
||||
var response = await _httpClient.PostAsJsonAsync("v1/Vault", vaultObject);
|
||||
|
||||
// 413: server / reverse-proxy rejected the upload because the vault exceeded MAX_UPLOAD_SIZE_MB.
|
||||
// Show the targeted message and skip the generic notification fired in the catch / fallthrough.
|
||||
if (response.StatusCode == HttpStatusCode.RequestEntityTooLarge)
|
||||
{
|
||||
_logger.LogError("Vault upload rejected by server with 413 Request Entity Too Large. The vault exceeds the server's configured MAX_UPLOAD_SIZE_MB.");
|
||||
_globalNotificationService.AddErrorMessage(_sharedLocalizer["VaultTooLargeError"], true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ensure the request was successful
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
@@ -926,13 +935,16 @@ public sealed class DbService : IDisposable
|
||||
}
|
||||
|
||||
_logger.LogError("Error during save: server response was empty or could not be deserialized.");
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error saving database to server.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Generic save failure (server error, network issue, malformed response, etc.). DbService owns
|
||||
// the user-facing error so callers only need to react to the bool return value.
|
||||
_globalNotificationService.AddErrorMessage(_sharedLocalizer["VaultSaveError"], true);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user