File tree Expand file tree Collapse file tree 4 files changed +22
-7
lines changed
libs/core/lib/xhr/xhr-functions Expand file tree Collapse file tree 4 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -259,10 +259,15 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
259
259
260
260
toast . success ( 'Updating payment' , { position : toast . POSITION . BOTTOM_RIGHT } )
261
261
try {
262
- const udpateMessage = await editPayment ( updates )
263
- toast . success ( udpateMessage , { position : toast . POSITION . BOTTOM_RIGHT } )
264
- } catch ( err ) {
265
- toast . error ( 'Failed to update payment' , { position : toast . POSITION . BOTTOM_RIGHT } )
262
+ const updateMessage = await editPayment ( updates )
263
+ toast . success ( updateMessage , { position : toast . POSITION . BOTTOM_RIGHT } )
264
+ } catch ( err :any ) {
265
+ if ( err ?. message ) {
266
+ toast . error ( err ?. message , { position : toast . POSITION . BOTTOM_RIGHT } )
267
+ } else {
268
+ toast . error ( 'Failed to update payment' , { position : toast . POSITION . BOTTOM_RIGHT } )
269
+ }
270
+
266
271
return
267
272
}
268
273
Original file line number Diff line number Diff line change
1
+ import { ApiError } from "./ApiError"
2
+
1
3
export default interface ApiResponse < T > {
2
4
status : 'success' | 'error'
3
5
data : T
6
+ error : ApiError
4
7
}
Original file line number Diff line number Diff line change @@ -79,10 +79,14 @@ export async function editPayment(updates: {
79
79
} ) : Promise < string > {
80
80
const body = JSON . stringify ( updates )
81
81
const url = `${ baseUrl } /admin/winnings`
82
-
82
+
83
83
const response = await xhrPatchAsync < string , ApiResponse < string > > ( url , body )
84
84
85
85
if ( response . status === 'error' ) {
86
+ if ( response . error && response . error . message ) {
87
+ console . log ( response . error . message )
88
+ throw new Error ( response . error . message )
89
+ }
86
90
throw new Error ( 'Error editing payment' )
87
91
}
88
92
Original file line number Diff line number Diff line change @@ -172,10 +172,13 @@ function interceptError(instance: AxiosInstance): void {
172
172
config => config ,
173
173
( error : any ) => {
174
174
// if there is server error message, then return it inside `message` property of error
175
- error . message = error ?. response ?. data ?. message || error . message
175
+ if ( error ?. response ?. data ?. message ) {
176
+ error . message = error ?. response ?. data ?. message
177
+ } else if ( error ?. response ?. data ?. error ?. message ) {
178
+ error . message = error ?. response ?. data ?. error ?. message
179
+ }
176
180
// if there is server errors data, then return it inside `errors` property of error
177
181
error . errors = error ?. response ?. data ?. errors
178
-
179
182
return Promise . reject ( error )
180
183
} ,
181
184
)
You can’t perform that action at this time.
0 commit comments