|
1 | 1 | import { PayloadAction, SerializedError, createSlice } from "@reduxjs/toolkit"; |
2 | 2 | import { eventsTableConfig } from "../configs/tableConfigs/eventsTableConfig"; |
3 | | -import axios, { AxiosProgressEvent } from "axios"; |
| 3 | +import axios, { AxiosError, AxiosProgressEvent } from "axios"; |
4 | 4 | import moment from "moment-timezone"; |
5 | 5 | import { |
6 | 6 | getURLParams, |
@@ -391,41 +391,44 @@ export const updateBulkMetadata = createAppAsyncThunk("events/updateBulkMetadata |
391 | 391 | }) |
392 | 392 | .catch(err => { |
393 | 393 | console.error(err); |
394 | | - // if an internal server error occurred, then backend sends further information |
395 | | - if (err.status === 500) { |
396 | | - // backend should send data containing further information about occurred internal error |
397 | | - // if this error data is undefined then an unexpected error occurred |
398 | | - if (!err.data) { |
399 | | - dispatch( |
400 | | - addNotification({ type: "error", key: "BULK_METADATA_UPDATE.UNEXPECTED_ERROR" }), |
401 | | - ); |
402 | | - } else { |
403 | | - if (err.data.updated && err.data.updated.length === 0) { |
404 | | - dispatch( |
405 | | - addNotification({ type: "error", key: "BULK_METADATA_UPDATE.NO_EVENTS_UPDATED" }), |
406 | | - ); |
407 | | - } |
408 | | - if (err.data.updateFailures && err.data.updateFailures.length > 0) { |
409 | | - dispatch( |
410 | | - addNotification({ |
411 | | - type: "warning", |
412 | | - key: "BULK_METADATA_UPDATE.SOME_EVENTS_NOT_UPDATED", |
413 | | - }), |
414 | | - ); |
415 | | - } |
416 | | - if (err.data.notFound && err.data.notFound.length > 0) { |
| 394 | + if (axios.isAxiosError<{ updated: string[], updateFailures: string[], notFound: string[] }>(err) && err.response) { |
| 395 | + // if an internal server error occurred, then backend sends further information |
| 396 | + if (err.status === 500) { |
| 397 | + // backend should send data containing further information about occurred internal error |
| 398 | + // if this error data is undefined then an unexpected error occurred |
| 399 | + const data = err.response.data; |
| 400 | + if (!data) { |
417 | 401 | dispatch( |
418 | | - addNotification({ |
419 | | - type: "warning", |
420 | | - key: "BULK_ACTIONS.EDIT_EVENTS_METADATA.REQUEST_ERRORS.NOT_FOUND", |
421 | | - }), |
| 402 | + addNotification({ type: "error", key: "BULK_METADATA_UPDATE.UNEXPECTED_ERROR" }), |
422 | 403 | ); |
| 404 | + } else { |
| 405 | + if (data.updated && data.updated.length === 0) { |
| 406 | + dispatch( |
| 407 | + addNotification({ type: "error", key: "BULK_METADATA_UPDATE.NO_EVENTS_UPDATED" }), |
| 408 | + ); |
| 409 | + } |
| 410 | + if (data.updateFailures && data.updateFailures.length > 0) { |
| 411 | + dispatch( |
| 412 | + addNotification({ |
| 413 | + type: "warning", |
| 414 | + key: "BULK_METADATA_UPDATE.SOME_EVENTS_NOT_UPDATED", |
| 415 | + }), |
| 416 | + ); |
| 417 | + } |
| 418 | + if (data.notFound && data.notFound.length > 0) { |
| 419 | + dispatch( |
| 420 | + addNotification({ |
| 421 | + type: "warning", |
| 422 | + key: "BULK_ACTIONS.EDIT_EVENTS_METADATA.REQUEST_ERRORS.NOT_FOUND", |
| 423 | + }), |
| 424 | + ); |
| 425 | + } |
423 | 426 | } |
| 427 | + } else { |
| 428 | + dispatch( |
| 429 | + addNotification({ type: "error", key: "BULK_METADATA_UPDATE.UNEXPECTED_ERROR" }), |
| 430 | + ); |
424 | 431 | } |
425 | | - } else { |
426 | | - dispatch( |
427 | | - addNotification({ type: "error", key: "BULK_METADATA_UPDATE.UNEXPECTED_ERROR" }), |
428 | | - ); |
429 | 432 | } |
430 | 433 | }); |
431 | 434 | }); |
@@ -680,9 +683,9 @@ export const deleteEvent = createAppAsyncThunk("events/deleteEvent", async (id: |
680 | 683 | dispatch(addNotification({ type: "success", key: "EVENT_WILL_BE_DELETED" })); |
681 | 684 | } |
682 | 685 | }) |
683 | | - .catch(res => { |
| 686 | + .catch((error: AxiosError) => { |
684 | 687 | // add error notification depending on status code |
685 | | - if (res.status === 401) { |
| 688 | + if (error.status === 401) { |
686 | 689 | dispatch(addNotification({ type: "error", key: "EVENTS_NOT_DELETED_NOT_AUTHORIZED" })); |
687 | 690 | } else { |
688 | 691 | dispatch(addNotification({ type: "error", key: "EVENTS_NOT_DELETED" })); |
|
0 commit comments