Browse Source

Handle error thrown in postConfigUpdateToAPI (#3299)

Co-authored-by: Tiffany L <tleugn@wpi.edu>
pull/3304/head
Tiffany 2 years ago committed by GitHub
parent
commit
9094ade2c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      web/utils/config-constants.tsx

25
web/utils/config-constants.tsx

@ -54,15 +54,22 @@ const TEXTFIELD_TYPE_URL = 'url'; @@ -54,15 +54,22 @@ const TEXTFIELD_TYPE_URL = 'url';
export async function postConfigUpdateToAPI(args: ApiPostArgs) {
const { apiPath, data, onSuccess, onError } = args;
const result = await fetchData(`${SERVER_CONFIG_UPDATE_URL}${apiPath}`, {
data,
method: 'POST',
auth: true,
});
if (result.success && onSuccess) {
onSuccess(result.message);
} else if (onError) {
onError(result.message);
try {
const result = await fetchData(`${SERVER_CONFIG_UPDATE_URL}${apiPath}`, {
data,
method: 'POST',
auth: true,
});
if (result.success && onSuccess) {
onSuccess(result.message);
} else if (onError) {
onError(result.message);
}
}
catch (e) {
if (onError) {
onError(e.message);
}
}
}

Loading…
Cancel
Save