mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Improved APIs to respond to unreachable error
This commit is contained in:
parent
b8efd638ae
commit
99d42f5125
2 changed files with 17 additions and 7 deletions
|
@ -51,7 +51,10 @@ export function UserRegister(register: RegistrationParams) {
|
|||
return [true, response.status];
|
||||
})
|
||||
.catch((error) => {
|
||||
return [false, error.response.status, error.response.data];
|
||||
let error_message = "";
|
||||
if (error.response) error_message = error.response.data;
|
||||
else error_message = "Unable to reach servers";
|
||||
return [false, error_message];
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -70,8 +73,10 @@ export function UserLogin(user: LoginParams) {
|
|||
return [true];
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Login Failed:" + JSON.stringify(error.response.data));
|
||||
return [false, error.response.data];
|
||||
let error_message = "";
|
||||
if (error.response) error_message = error.response.data;
|
||||
else error_message = "Unable to reach servers";
|
||||
return [false, error_message];
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -91,7 +96,10 @@ export async function TokenRefresh() {
|
|||
return true;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Refresh Failed: " + JSON.stringify(error.response));
|
||||
let error_message = "";
|
||||
if (error.response) error_message = error.response.data;
|
||||
else error_message = "Unable to reach servers";
|
||||
console.log("Token Refresh error:", error_message);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
@ -108,8 +116,10 @@ export async function UserInfo() {
|
|||
return response.data;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("User Info Error", error.response.data);
|
||||
return [false, error.response.data];
|
||||
let error_message = "";
|
||||
if (error.response) error_message = error.response.data;
|
||||
else error_message = "Unable to reach servers";
|
||||
return [false, error_message];
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ export default function Register() {
|
|||
} else {
|
||||
setUser({
|
||||
...user,
|
||||
feedback: ParseError(JSON.stringify(result[2])),
|
||||
feedback: ParseError(JSON.stringify(result[1])),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue