From 0e4e5b46ada58bf7a1bc3c576271490f3bfa9821 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 13 Sep 2020 18:49:45 +0300 Subject: [PATCH] Migration: properly handle field-specific errors. --- src/MigrateV2.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/MigrateV2.tsx b/src/MigrateV2.tsx index a5dfbc3..ac55c6c 100644 --- a/src/MigrateV2.tsx +++ b/src/MigrateV2.tsx @@ -188,7 +188,24 @@ export function WizardAccountPage(props: OurPagePropsType & { setEtebase: (eteba props.next?.(); setProgress("Done"); } catch (e) { - if (e instanceof Etebase.UnauthorizedError) { + if ((e instanceof Etebase.HttpError) && (e.content)) { + let found = false; + if (e.content.errors) { + for (const field of e.content.errors) { + if (field.field === "user.username") { + errors.errorEmail = field.detail; + found = true; + } else if (!field.field) { + errors.errorGeneral = field.detail; + found = true; + } + } + } + + if (!found) { + errors.errorGeneral = e.content.detail ?? e.toString(); + } + } else if (e instanceof Etebase.UnauthorizedError) { errors.errorGeneral = "Wrong username or password"; } else { errors.errorGeneral = e.toString();