From ef55153810b2269cf66465d86d164bf419c7ad03 Mon Sep 17 00:00:00 2001 From: Bernt Andreas Drange Date: Wed, 2 Oct 2019 12:01:12 +0300 Subject: [PATCH 1/2] Show errors to staff members if comment adding or editing of reservations fail --- src/common/api/client.js | 11 ++++--- .../manage/page/ManageReservationsPage.js | 30 ++++++++++++------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/common/api/client.js b/src/common/api/client.js index 86784ba6d..295759693 100644 --- a/src/common/api/client.js +++ b/src/common/api/client.js @@ -7,6 +7,13 @@ import { parseData } from '../data/utils'; let authToken; +// Response interceptor to be able to handle errors. +axios.interceptors.response.use((response) => { + return response; +}, (error) => { + return Promise.reject(error.response); +}); + const getToken = () => { const state = store.getState(); return get(state, 'auth.token'); @@ -58,10 +65,6 @@ export class ApiClient { .then(response => ({ data: get(response, 'data'), error: null, - })) - .catch(error => ({ - data: null, - error: get(error, 'response'), })); }; diff --git a/src/domain/reservation/manage/page/ManageReservationsPage.js b/src/domain/reservation/manage/page/ManageReservationsPage.js index cd18d84d7..198eac607 100644 --- a/src/domain/reservation/manage/page/ManageReservationsPage.js +++ b/src/domain/reservation/manage/page/ManageReservationsPage.js @@ -12,8 +12,10 @@ import { createStructuredSelector } from 'reselect'; import PageWrapper from '../../../../../app/pages/PageWrapper'; import injectT from '../../../../../app/i18n/injectT'; import client from '../../../../common/api/client'; +import { createNotification } from '../../../../common/notification/utils'; import ManageReservationsFilters from '../filters/ManageReservationsFilters'; import ManageReservationsList from '../list/ManageReservationsList'; +import { NOTIFICATION_TYPE } from '../../../../common/notification/constants'; import Pagination from '../../../../common/pagination/Pagination'; import * as searchUtils from '../../../search/utils'; import { selectReservationToEdit } from '../../../../../app/actions/uiActions'; @@ -137,20 +139,28 @@ class ManageReservationsPage extends React.Component { })); } - onEditReservation = (reservation, status) => { - if (status === RESERVATION_STATE.CANCELLED) { - reservationUtils.cancelReservation(reservation).then(() => this.loadReservations()); - } else { - reservationUtils.putReservation(reservation, { state: status }).then(() => { - this.loadReservations(); - }); + onEditReservation = async (reservation, status) => { + try { + if (status === RESERVATION_STATE.CANCELLED) { + await reservationUtils.cancelReservation(reservation); + } else { + await reservationUtils.putReservation(reservation, { state: status }); + } + this.loadReservations(); + } catch (error) { + // We show the error message from respa to staff because it helps with support and debugging. + createNotification(NOTIFICATION_TYPE.ERROR, error.data.detail); } } - onSaveComment = (reservation, comments) => { - return reservationUtils.putReservation(reservation, { resource: reservation.resource.id, comments }).then(() => { + onSaveComment = async (reservation, comments) => { + try { + await reservationUtils.putReservation(reservation, { resource: reservation.resource.id, comments }); this.loadReservations(); - }); + } catch (error) { + // We show the error message from respa to staff because it helps with support and debugging. + createNotification(NOTIFICATION_TYPE.ERROR, error.data.detail); + } }; /** From b065982226e39fd5ca6b407cc38a7522c3a43a32 Mon Sep 17 00:00:00 2001 From: Bernt Andreas Drange Date: Wed, 2 Oct 2019 12:04:16 +0300 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 836eab830..03ec25606 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Add `show_only` filter section to filter reservation list. This filter have `can_modify` as its default value. - Anonymous users now see a log in button below the calendar on the resource page helping them understand that they need to log in to continue. - Fix FullCalendar not auto-select minPeriod time slot when user select. Various fixes related to edit reservation calendar, drag and drop and select error handler. + - Errors from respa backend are not swallowed in our ApiClient anymore. **HOTFIX** - Fix resource information headlines and icon. @@ -27,6 +28,7 @@ - [#1027](https://github.com/City-of-Helsinki/varaamo/pull/1027) Improve resource page usability for anonymous users. - [#1028](https://github.com/City-of-Helsinki/varaamo/pull/1028) Always fetch reservations with start and end filters. - [#1029](https://github.com/City-of-Helsinki/varaamo/pull/1029) Add option to configure time zone for resources. + - [#1033](https://github.com/City-of-Helsinki/varaamo/pull/1033) Show errors to staff members if editing of reservations fail. # 0.4.2 **HOTFIX**