Skip to content

Commit 354c9bb

Browse files
Merge pull request #62 from nirupama-dev/bug-extract-error-message
Showed only message field in error toast for creating vertex schedule
2 parents 142c57f + 64775a2 commit 354c9bb

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/services/Vertex.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
import { toast } from 'react-toastify';
1818
import { requestAPI } from '../handler/Handler';
1919
import { SchedulerLoggingService, LOG_LEVEL } from './LoggingService';
20-
import { showToast, toastifyCustomStyle } from '../utils/Config';
20+
import {
21+
showToast,
22+
toastifyCustomStyle,
23+
toastifyCustomWidth
24+
} from '../utils/Config';
2125
import {
2226
ICreatePayload,
2327
IVertexScheduleList,
@@ -98,10 +102,28 @@ export class VertexServices {
98102
method: 'POST'
99103
});
100104
if (data.error) {
101-
toast.error(
102-
<ExpandToastMessage message={data.error} />,
103-
toastifyCustomStyle
105+
const jsonstr = data?.error.slice(
106+
data?.error.indexOf('{'),
107+
data?.error.lastIndexOf('}') + 1
104108
);
109+
if (jsonstr) {
110+
const errorObject = JSON.parse(jsonstr);
111+
if (errorObject.error.message) {
112+
toast.error(
113+
`Error in creating schedule : ${errorObject.error.message}`,
114+
{
115+
...toastifyCustomStyle
116+
}
117+
);
118+
} else {
119+
toast.error(
120+
<ExpandToastMessage message={data.error} />,
121+
data.error.length > 500
122+
? toastifyCustomWidth
123+
: toastifyCustomStyle
124+
);
125+
}
126+
}
105127
setCreatingVertexScheduler(false);
106128
} else {
107129
toast.success(

src/utils/Config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ export const toastifyCustomStyle: ToastOptions<Record<string, never>> = {
7676
position: toast.POSITION.BOTTOM_CENTER
7777
};
7878

79+
export const toastifyCustomWidth: ToastOptions<Record<string, never>> = {
80+
hideProgressBar: true,
81+
autoClose: 600000,
82+
theme: 'dark',
83+
position: toast.POSITION.BOTTOM_CENTER,
84+
style: {
85+
width: '150%'
86+
}
87+
};
88+
7989
export const handleDebounce = (func: any, delay: number) => {
8090
let timeoutId: any;
8191
return function (...args: any) {

0 commit comments

Comments
 (0)