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];
|
return [true, response.status];
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.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];
|
return [true];
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("Login Failed:" + JSON.stringify(error.response.data));
|
let error_message = "";
|
||||||
return [false, error.response.data];
|
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;
|
return true;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.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;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -108,8 +116,10 @@ export async function UserInfo() {
|
||||||
return response.data;
|
return response.data;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("User Info Error", error.response.data);
|
let error_message = "";
|
||||||
return [false, error.response.data];
|
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 {
|
} else {
|
||||||
setUser({
|
setUser({
|
||||||
...user,
|
...user,
|
||||||
feedback: ParseError(JSON.stringify(result[2])),
|
feedback: ParseError(JSON.stringify(result[1])),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue