@@ -41,6 +41,15 @@ import TestMigrationLogViewer from '../LogScreen';
4141// CSS
4242import './index.scss' ;
4343
44+ interface ErrorObject {
45+ error_message ?: string ;
46+ errors ?: Errors ;
47+ }
48+
49+ interface Errors {
50+ org_uid ?: string [ ] ;
51+ }
52+
4453const TestMigration = ( ) => {
4554 // Access Redux state for migration data and selected organization
4655 const newMigrationData = useSelector ( ( state : RootState ) => state ?. migration ?. newMigrationData ) ;
@@ -174,15 +183,15 @@ const TestMigration = () => {
174183 data
175184 ) ;
176185
177- if ( res ?. status === 200 ) {
186+ if ( res ?. status === 201 ) {
178187 setIsStackLoading ( false ) ;
179188 setDisableCreateStack ( true ) ;
180189 setDisableTestMigration ( false ) ;
181190 Notification ( {
182- notificationContent : { text : 'Test Stack created successfully' } ,
191+ notificationContent : { text : res ?. data ?. data ?. data ?. notice ?? 'Test Stack created successfully' } ,
183192 notificationProps : {
184193 position : 'bottom-center' ,
185- hideProgressBar : false
194+ hideProgressBar : true
186195 } ,
187196 type : 'success'
188197 } ) ;
@@ -206,20 +215,38 @@ const TestMigration = () => {
206215 ]
207216 } ;
208217 dispatch ( updateNewMigrationData ( newMigrationDataObj ) ) ;
218+ } else {
219+ const errorMessage = formatErrorMessage ( res ?. data ?. data ) ;
220+ setIsStackLoading ( false ) ;
221+ Notification ( {
222+ notificationContent : { text : errorMessage } ,
223+ notificationProps : {
224+ position : 'bottom-center' ,
225+ hideProgressBar : true
226+ } ,
227+ type : 'error'
228+ } ) ;
209229 }
210230 } catch ( err ) {
211231 console . error ( err ) ;
212- Notification ( {
213- notificationContent : { text : err } ,
214- notificationProps : {
215- position : 'bottom-center' ,
216- hideProgressBar : true
217- } ,
218- type : 'error'
219- } ) ;
220232 }
221233 } ;
222234
235+ /**
236+ * Function to format the error message
237+ */
238+ const formatErrorMessage = ( errorData : ErrorObject ) => {
239+ let message = errorData . error_message ;
240+
241+ if ( errorData . errors ) {
242+ Object . entries ( errorData . errors ) . forEach ( ( [ key , value ] ) => {
243+ message += `\n${ key } : ${ ( value as string [ ] ) . join ( ", " ) } ` ;
244+ } ) ;
245+ }
246+
247+ return message ;
248+ }
249+
223250 /**
224251 * Start the test migration
225252 */
@@ -256,7 +283,7 @@ const TestMigration = () => {
256283 notificationContent : { text : 'Test Migration started' } ,
257284 notificationProps : {
258285 position : 'bottom-center' ,
259- hideProgressBar : false
286+ hideProgressBar : true
260287 } ,
261288 type : 'message'
262289 } ) ;
0 commit comments