aboutsummaryrefslogtreecommitdiffstats
path: root/code/app/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'code/app/src/lib')
-rw-r--r--code/app/src/lib/models/internal/FormError.ts24
-rw-r--r--code/app/src/lib/services/abstractions/IAccountService.ts3
-rw-r--r--code/app/src/lib/services/account-service.ts9
3 files changed, 34 insertions, 2 deletions
diff --git a/code/app/src/lib/models/internal/FormError.ts b/code/app/src/lib/models/internal/FormError.ts
new file mode 100644
index 0000000..f6d8978
--- /dev/null
+++ b/code/app/src/lib/models/internal/FormError.ts
@@ -0,0 +1,24 @@
+import type { KnownProblem } from "./KnownProblem";
+
+export class FormError {
+ title: string;
+ subtitle: string;
+ constructor(title: string = "", subtitle: string = "") {
+ this.title = title;
+ this.title = subtitle;
+ }
+
+ set(title: string = "", subtitle: string = "") {
+ this.title = title;
+ this.subtitle = subtitle;
+ }
+
+ set_from_known_problem(knownProblem: KnownProblem) {
+ this.title = knownProblem.title ?? "";
+ this.subtitle = knownProblem.subtitle ?? "";
+ }
+
+ has_error() {
+ return this.title?.length > 0 || this.subtitle?.length > 0;
+ }
+} \ No newline at end of file
diff --git a/code/app/src/lib/services/abstractions/IAccountService.ts b/code/app/src/lib/services/abstractions/IAccountService.ts
index 736c3ae..2beeb08 100644
--- a/code/app/src/lib/services/abstractions/IAccountService.ts
+++ b/code/app/src/lib/services/abstractions/IAccountService.ts
@@ -25,7 +25,8 @@ export type LoginPayload = {
}
export type LoginResponse = {
- isLoggedIn: boolean
+ isLoggedIn: boolean,
+ knownProblem?: KnownProblem
}
export type CreateAccountPayload = {
diff --git a/code/app/src/lib/services/account-service.ts b/code/app/src/lib/services/account-service.ts
index 90af163..dedf39e 100644
--- a/code/app/src/lib/services/account-service.ts
+++ b/code/app/src/lib/services/account-service.ts
@@ -7,7 +7,14 @@ export class AccountService implements IAccountService {
session: Session;
async login_async(payload: LoginPayload): Promise<LoginResponse> {
const response = await http_post_async(api_base("_/account/login"), payload);
- return { isLoggedIn: response.ok };
+ if (response.ok) return { isLoggedIn: true };
+ if (is_known_problem(response)) return {
+ isLoggedIn: false,
+ knownProblem: await response.json()
+ };
+ return {
+ isLoggedIn: false
+ }
}
async logout_async(): Promise<void> {
const response = await http_get_async(api_base("_/account/logout"));