Skip to content

Commit

Permalink
Merge pull request #1357 from RoundingWell/explict-errors
Browse files Browse the repository at this point in the history
Generic errors need to be more explicit
  • Loading branch information
paulfalgout authored Dec 3, 2024
2 parents cd73795 + ebe7f33 commit 01c416e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
17 changes: 9 additions & 8 deletions src/js/apps/patients/patient/flow/flow_app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { bind, invoke } from 'underscore';
import { bind, invoke, get } from 'underscore';
import Backbone from 'backbone';
import Radio from 'backbone.radio';

import intl, { renderTemplate } from 'js/i18n';
import handleErrors from 'js/utils/handle-errors';

import SubRouterApp from 'js/base/subrouterapp';

Expand Down Expand Up @@ -49,20 +50,20 @@ export default SubRouterApp.extend({
Radio.request('entities', 'fetch:patients:model:byFlow', flowId),
];
},
onFail(options, { response = {} }) {
/* istanbul ignore else: other error scenarios handled elsewhere */
if (response.status === 410) {
/* istanbul ignore next: error handling */
onFail(options, error) {
if (get(error, ['response', 'status']) === 410) {
Radio.trigger('event-router', 'notFound');
this.stop();
return;
}

/* eslint-disable no-console */
console.error(arguments);

handleErrors(error);
},
onStart({ currentRoute }, flow, actions, patient) {
this.flow = flow;
this.actions = actions;
this.currentRoute = currentRoute;
this.editableCollection = actions.clone();
this.patient = patient;
this.addOpts = this.getAddOpts(this.flow.getProgramFlow());
Expand Down Expand Up @@ -209,7 +210,7 @@ export default SubRouterApp.extend({
.catch(() => {
Radio.request('alert', 'show:error', intl.patients.worklist.worklistApp.bulkEditFailure);
this.getState().clearSelected();
this.restart();
this.restart({ flowId: this.flow.id, currentRoute: this.currentRoute });
});
},
'delete'() {
Expand Down
13 changes: 7 additions & 6 deletions src/js/apps/patients/patient/patient_app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { partial, some, get } from 'underscore';
import Radio from 'backbone.radio';

import handleErrors from 'js/utils/handle-errors';

import SubRouterApp from 'js/base/subrouterapp';

import DashboardApp from 'js/apps/patients/patient/dashboard/dashboard_app';
Expand Down Expand Up @@ -46,10 +48,10 @@ export default SubRouterApp.extend({
},

/* istanbul ignore next: error handling */
onFail({ currentRoute: { eventArgs: [patientId] } }, { response = {}, responseData = {} }) {
if (response.status === 410) {
if (!some(responseData.errors, error => {
return get(error, ['source', 'parameter']) === 'actionId';
onFail({ currentRoute: { eventArgs: [patientId] } }, error) {
if (get(error, ['response', 'status']) === 410) {
if (!some(error.responseData.errors, err => {
return get(err, ['source', 'parameter']) === 'actionId';
})) {
Radio.trigger('event-router', 'notFound');
this.stop();
Expand All @@ -62,8 +64,7 @@ export default SubRouterApp.extend({
return;
}

/* eslint-disable no-console */
console.error(arguments);
handleErrors(error);
},

onStart({ currentRoute }, patient) {
Expand Down
24 changes: 22 additions & 2 deletions test/integration/patients/patient/patient-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,8 @@ context('patient flow page', function() {
});

specify('bulk edit actions', function() {
const testPatient = getPatient();

const testFlowActions = [
getAction({
attributes: {
Expand All @@ -1484,6 +1486,7 @@ context('patient flow page', function() {
sequence: 1,
},
relationships: {
patient: getRelationship(testPatient),
flow: getRelationship(testFlow),
state: getRelationship(stateTodo),
owner: getRelationship(teamNurse),
Expand All @@ -1498,6 +1501,7 @@ context('patient flow page', function() {
sequence: 3,
},
relationships: {
patient: getRelationship(testPatient),
flow: getRelationship(testFlow),
state: getRelationship(stateTodo),
owner: getRelationship(teamOther),
Expand All @@ -1511,6 +1515,7 @@ context('patient flow page', function() {
sequence: 3,
},
relationships: {
patient: getRelationship(testPatient),
flow: getRelationship(testFlow),
state: getRelationship(stateInProgress),
owner: getRelationship(teamOther),
Expand All @@ -1526,14 +1531,19 @@ context('patient flow page', function() {
updated_at: testTs(),
},
relationships: {
patient: getRelationship(testPatient),
state: getRelationship(stateInProgress),
actions: getRelationship(testFlowActions),
},
});

return fx;
})
.routePatientByFlow()
.routePatientByFlow(fx => {
fx.data = testPatient;

return fx;
})
.routeFlowActions(fx => {
fx.data = testFlowActions;

Expand Down Expand Up @@ -1971,7 +1981,7 @@ context('patient flow page', function() {

cy
.intercept('PATCH', '/api/actions/*', {
statusCode: 404,
statusCode: 400,
body: {},
})
.as('failedPatchAction');
Expand Down Expand Up @@ -2005,6 +2015,16 @@ context('patient flow page', function() {
cy
.get('.alert-box')
.should('contain', 'Something went wrong. Please try again.');

cy
.wait('@routeFlow')
.wait('@routePatientByFlow')
.wait('@routeFlowActions');

cy
.get('.app-frame__content')
.find('.table-list__item')
.should('have.length', 3);
});

specify('click+shift multiselect', function() {
Expand Down

0 comments on commit 01c416e

Please sign in to comment.