mirror of
https://github.com/ansible/awx.git
synced 2026-01-18 21:21:21 -03:30
add more robust handling of errors thrown by api
This commit is contained in:
parent
b8226109a7
commit
0f9c906a22
@ -53,8 +53,13 @@ class ErrorDetail extends Component {
|
||||
const { error } = this.props;
|
||||
const { response } = error;
|
||||
|
||||
const message =
|
||||
typeof response.data === 'string' ? response.data : response.data.detail;
|
||||
let message = '';
|
||||
if (response.data) {
|
||||
message =
|
||||
typeof response.data === 'string'
|
||||
? response.data
|
||||
: response.data?.detail;
|
||||
}
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
|
||||
@ -27,7 +27,8 @@ function HostAdd({ i18n }) {
|
||||
const { data: response } = await HostsAPI.create(values);
|
||||
history.push(`${url}/${response.id}/details`);
|
||||
} catch (error) {
|
||||
if (error.response?.data) {
|
||||
// check for field-specific errors from API
|
||||
if (error.response?.data && typeof error.response.data === 'object') {
|
||||
throw error.response.data;
|
||||
}
|
||||
setFormError(error);
|
||||
|
||||
@ -35,7 +35,8 @@ function HostEdit({ host, i18n }) {
|
||||
await HostsAPI.update(host.id, values);
|
||||
history.push(detailsUrl);
|
||||
} catch (error) {
|
||||
if (error.response?.data) {
|
||||
// check for field-specific errors from API
|
||||
if (error.response?.data && typeof error.response.data === 'object') {
|
||||
throw error.response.data;
|
||||
}
|
||||
setFormError(error);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user