Skip to content

Commit

Permalink
Have the workpad service show 404 notification if the saved object to…
Browse files Browse the repository at this point in the history
… load is not found (elastic#709)

* workpad service: show 404 error from workpad saved object not found

* make the notification say "Canvas"

* Notifier not a constructor?
  • Loading branch information
tsullivan authored Jun 21, 2018
1 parent 67111fe commit 9a8778e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
12 changes: 8 additions & 4 deletions public/apps/workpad/routes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as workpadService from '../../lib/workpad_service';
import { notify } from '../../lib/notify';
import { getDefaultWorkpad } from '../../state/defaults';
import { setWorkpad } from '../../state/actions/workpad';
import { setAssets, resetAssets } from '../../state/actions/assets';
Expand Down Expand Up @@ -32,10 +33,13 @@ export const routes = [
// load workpad if given a new id via url param
const currentWorkpad = getWorkpad(getState());
if (params.id !== currentWorkpad.id) {
// TODO: handle missing/invalid workpad id's (mostly 404)
const { assets, ...workpad } = await workpadService.get(params.id);
dispatch(setWorkpad(workpad));
dispatch(setAssets(assets));
try {
const { assets, ...workpad } = await workpadService.get(params.id);
dispatch(setWorkpad(workpad));
dispatch(setAssets(assets));
} catch (fetchErr) {
notify.error(fetchErr);
}
}

// fetch the workpad again, to get changes
Expand Down
2 changes: 1 addition & 1 deletion public/components/workpad_loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const WorkpadLoader = compose(
withHandlers({
// Workpad creation via navigation
createWorkpad: props => async workpad => {
// workpad passed in, create and load it
// workpad data uploaded, create and load it
if (workpad != null) {
await workpadService.create(workpad);
props.router.navigateTo('loadWorkpad', { id: workpad.id, page: 1 });
Expand Down
8 changes: 6 additions & 2 deletions public/lib/notify.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { notify as kbnNotify } from 'ui/notify';

export const notify = {
error(msg, opts = {}) {
kbnNotify.error(msg, opts);
/*
* @param {Object} err: Error object
* @param {Object} opts: option to override notification icon
*/
error(err, opts = {}) {
kbnNotify.error(err, opts);
},
warning(msg, opts = {}) {
kbnNotify.warning(msg, opts);
Expand Down
5 changes: 4 additions & 1 deletion public/lib/workpad_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export function create(workpad) {
}

export function get(workpadId) {
return fetch.get(`${apiPath}/${workpadId}`).then(res => res.data);
return fetch
.get(`${apiPath}/${workpadId}`)
.then(res => res.data)
.catch(({ response }) => Promise.reject(response));
}

export function update(id, workpad) {
Expand Down
3 changes: 2 additions & 1 deletion server/routes/workpad.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export function workpad(server) {
return savedObjectsClient
.get(CANVAS_TYPE, id)
.then(obj => obj.attributes)
.then(formatResponse(reply));
.then(formatResponse(reply))
.catch(formatResponse(reply));
},
});

Expand Down

0 comments on commit 9a8778e

Please sign in to comment.