[Saved Objects Client] Return info about what was missing in the 404 (#19868)

* [Saved Objects Client] Return info about what was missing in the 404 error

* update api integration tests

* fix another test
This commit is contained in:
Tim Sullivan 2018-06-15 16:14:04 -07:00 committed by GitHub
parent bdebff91fb
commit 633aa4250f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 10 deletions

View file

@ -73,7 +73,10 @@ export function isForbiddenError(error) {
// 404 - Not Found
const CODE_NOT_FOUND = 'SavedObjectsClient/notFound';
export function createGenericNotFoundError() {
export function createGenericNotFoundError(type = null, id = null) {
if (type && id) {
return decorate(Boom.notFound(`Saved object [${type}/${id}] not found`), CODE_NOT_FOUND, 404);
}
return decorate(Boom.notFound(), CODE_NOT_FOUND, 404);
}
export function isNotFoundError(error) {

View file

@ -193,7 +193,7 @@ export class SavedObjectsRepository {
const indexNotFound = response.error && response.error.type === 'index_not_found_exception';
if (docNotFound || indexNotFound) {
// see "404s from missing index" above
throw errors.createGenericNotFoundError();
throw errors.createGenericNotFoundError(type, id);
}
throw new Error(
@ -352,7 +352,7 @@ export class SavedObjectsRepository {
const indexNotFound = response.status === 404;
if (docNotFound || indexNotFound) {
// see "404s from missing index" above
throw errors.createGenericNotFoundError();
throw errors.createGenericNotFoundError(type, id);
}
const { updated_at: updatedAt } = response._source;
@ -394,7 +394,7 @@ export class SavedObjectsRepository {
if (response.status === 404) {
// see "404s from missing index" above
throw errors.createGenericNotFoundError();
throw errors.createGenericNotFoundError(type, id);
}
return {

View file

@ -46,7 +46,7 @@ export default function ({ getService }) {
expect(resp.body).to.eql({
statusCode: 404,
error: 'Not Found',
message: 'Not Found'
message: 'Saved object [dashboard/not-a-real-id] not found'
});
})
));
@ -69,7 +69,7 @@ export default function ({ getService }) {
expect(resp.body).to.eql({
statusCode: 404,
error: 'Not Found',
message: 'Not Found'
message: 'Saved object [dashboard/be3733a0-9efe-11e7-acb3-3dab96693fab] not found'
});
})
));

View file

@ -60,7 +60,7 @@ export default function ({ getService }) {
.then(resp => {
expect(resp.body).to.eql({
error: 'Not Found',
message: 'Not Found',
message: 'Saved object [visualization/foobar] not found',
statusCode: 404,
});
})
@ -84,7 +84,7 @@ export default function ({ getService }) {
.then(resp => {
expect(resp.body).to.eql({
error: 'Not Found',
message: 'Not Found',
message: 'Saved object [visualization/dd7caf20-9efd-11e7-acb3-3dab96693fab] not found',
statusCode: 404,
});
})

View file

@ -70,7 +70,7 @@ export default function ({ getService }) {
expect(resp.body).eql({
statusCode: 404,
error: 'Not Found',
message: 'Not Found'
message: 'Saved object [visualization/not an id] not found'
});
});
});
@ -99,7 +99,7 @@ export default function ({ getService }) {
expect(resp.body).eql({
statusCode: 404,
error: 'Not Found',
message: 'Not Found'
message: 'Saved object [visualization/dd7caf20-9efd-11e7-acb3-3dab96693fab] not found'
});
})
));