mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-17 03:53:06 +00:00
feat(automation): improve definition and trigger editing
This commit is contained in:
committed by
Carlos Valente
parent
79c21daf73
commit
b07544ab84
@@ -0,0 +1,25 @@
|
||||
import { maybeAxiosError } from '../utils';
|
||||
|
||||
describe('maybeAxiosError', () => {
|
||||
it('shows the validation message without echoing the submitted value', () => {
|
||||
const error = {
|
||||
isAxiosError: true,
|
||||
response: {
|
||||
statusText: 'Unprocessable Entity',
|
||||
data: {
|
||||
errors: [
|
||||
{
|
||||
type: 'field',
|
||||
value: { title: 'Automation definition', outputs: [{ targetIP: 'not a host' }] },
|
||||
msg: 'Invalid OSC target',
|
||||
path: '',
|
||||
location: 'body',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(maybeAxiosError(error)).toBe('Unprocessable Entity: Invalid OSC target');
|
||||
});
|
||||
});
|
||||
@@ -18,6 +18,15 @@ export function maybeAxiosError(error: unknown) {
|
||||
if (typeof data === 'object') {
|
||||
if ('message' in data) {
|
||||
data = JSON.stringify(data.message);
|
||||
} else if ('errors' in data && Array.isArray(data.errors)) {
|
||||
const firstError = data.errors.at(0);
|
||||
data =
|
||||
typeof firstError === 'object' &&
|
||||
firstError !== null &&
|
||||
'msg' in firstError &&
|
||||
typeof firstError.msg === 'string'
|
||||
? firstError.msg
|
||||
: JSON.stringify(data);
|
||||
} else {
|
||||
data = JSON.stringify(data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user