Skip to content

Commit

Permalink
Fix up error message for generic error types on login.
Browse files Browse the repository at this point in the history
  • Loading branch information
MelissaAutumn committed Dec 17, 2024
1 parent defd529 commit 834aef4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions frontend/src/composables/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ const instance = createI18n({

export default instance;
export const i18n = instance.global;
export type i18nType = typeof i18n.t;
2 changes: 1 addition & 1 deletion frontend/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const fxaEditProfileUrlKey = Symbol('fxaEditProfileUrl') as InjectionKey<
// Provide configured fetch call to our backend API
export const callKey = Symbol('call') as InjectionKey<Fetch>;

// Provide a freresh data function
// Provide a refresh data function
export const refreshKey = Symbol('refresh') as InjectionKey<Refresh>;

// Provide functionality to paint background of event objects
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// get the first key of given object that points to given value
import { ColorSchemes } from '@/definitions';
import { Ref } from 'vue';
import { i18nType } from '@/composables/i18n';
import {
CustomEventData, Coloring, EventPopup, HTMLElementEvent, CalendarEvent, PydanticException,
} from './models';
Expand Down Expand Up @@ -166,9 +167,10 @@ export const getAccessibleColor = (hexcolor: string): string => {
* @param formRef
* @param errObj
*/
export const handleFormError = (i18n: any, formRef: Ref, errObj: PydanticException) => {
export const handleFormError = (i18n: i18nType, formRef: Ref, errObj: PydanticException) => {
const unknownError = i18n('error.somethingWentWrong');
if (!errObj) {
return i18n('error.somethingWentWrong');
return unknownError;
}

const fields = formRef.value.elements;
Expand All @@ -186,7 +188,7 @@ export const handleFormError = (i18n: any, formRef: Ref, errObj: PydanticExcepti
} else if (typeof detail === 'string') { // HttpException errors are just strings
return detail;
} else {
return detail.message;
return detail?.message ?? unknownError;
}

// Finally report it!
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/views/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ const login = async () => {
const { error }: Error = await user.login(call, email.value, password.value);
if (error) {
handleFormError(error as PydanticException);
let errObj = error as PydanticException;
if (typeof error === 'string') {
errObj = { detail: error };
}
loginError.value = handleFormError(t, formRef, errObj);
isLoading.value = false;
return;
}
Expand Down

0 comments on commit 834aef4

Please sign in to comment.