store/enhancedImageBuilderApi: handle empty error data

Turns out it can also return `{error: data: {}}`, so without `errors`
inside the data object.
This commit is contained in:
Sanne Raymaekers 2024-12-09 16:47:28 +01:00 committed by Klara Simickova
parent 3addcf66f4
commit 3dcafd5672

View file

@ -5,7 +5,11 @@ import { imageBuilderApi } from './imageBuilderApi';
/* eslint-disable @typescript-eslint/no-explicit-any */
const errorMessage = (err: any) => {
let msg = err.error.statusText;
if (err.error.data?.errors.length > 0 && err.error.data?.errors[0]?.detail) {
if (
err.error.data?.errors &&
err.error.data?.errors.length > 0 &&
err.error.data?.errors[0]?.detail
) {
msg = err.error.data?.errors[0]?.detail;
}
return msg;