Skip to content

Commit

Permalink
Merge pull request #80 from UoaWDCC/fix-register-type-error
Browse files Browse the repository at this point in the history
fixing type error on msg
  • Loading branch information
Kinzi-c authored Sep 22, 2024
2 parents 187b76a + cba29ef commit c212be3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion web/src/api/register.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {apiInstance} from "@/api/ApiInstance";
import {UserState} from "@/app/features/user/userSlice";
import {stringToRole} from "@/app/type/role";
import axios from "axios";

export interface createFSAEUserDto {
email: string;
Expand Down Expand Up @@ -44,7 +45,10 @@ async function register(url: string, createUserDto: createFSAEUserDto): Promise<
}
} catch (e) {
console.log(e)
let errorMsg = e.response.data.error.message
let errorMsg = 'Error creating admin';
if (axios.isAxiosError(e) && e.response) {
errorMsg = e.response.data.error.message || errorMsg;
}
// If errorMsg not null display it, else say generic error message
errorMsg = errorMsg ? errorMsg : 'Error creating admin'
throw Error(errorMsg)
Expand Down

0 comments on commit c212be3

Please sign in to comment.