Handle error thrown in postConfigUpdateToAPI (#3299)

Co-authored-by: Tiffany L <tleugn@wpi.edu>
This commit is contained in:
Tiffany 2023-09-11 04:07:46 +10:00 committed by GitHub
parent d4428d168b
commit 9094ade2c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,6 +54,7 @@ const TEXTFIELD_TYPE_URL = 'url';
export async function postConfigUpdateToAPI(args: ApiPostArgs) {
const { apiPath, data, onSuccess, onError } = args;
try {
const result = await fetchData(`${SERVER_CONFIG_UPDATE_URL}${apiPath}`, {
data,
method: 'POST',
@ -64,6 +65,12 @@ export async function postConfigUpdateToAPI(args: ApiPostArgs) {
} else if (onError) {
onError(result.message);
}
}
catch (e) {
if (onError) {
onError(e.message);
}
}
}
// Some default props to help build out a TextField