Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove try/catch for short url so the appropriate errors will be propagated to the UI #13004

Merged
merged 15 commits into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
b62b879
Remove try/catch for short url so the appropriate errors will be prop…
stacey-gammon Jul 20, 2017
2295921
Simply ensure the error is a Boom error by wrapping it, but keep the …
stacey-gammon Jul 20, 2017
5b90bc8
Merge branch 'master' of https://github.com/elastic/kibana into fix/s…
stacey-gammon Jul 20, 2017
b836eeb
Merge branch 'master' of https://github.com/elastic/kibana into fix/s…
stacey-gammon Jul 21, 2017
3873b33
Merge branch 'master' of https://github.com/elastic/kibana into fix/s…
stacey-gammon Jul 21, 2017
a729049
Merge branch 'master' of https://github.com/elastic/kibana into fix/s…
stacey-gammon Jul 21, 2017
716eea2
Merge branch 'master' of https://github.com/elastic/kibana into fix/s…
stacey-gammon Jul 24, 2017
d5f622f
Boom.wrap can't handle non Error instances, as exist in some of the t…
stacey-gammon Jul 24, 2017
9cd4ce4
Merge branch 'master' of https://github.com/elastic/kibana into fix/s…
stacey-gammon Jul 25, 2017
109a67f
Only support Error objects, and check both status and statusCode
stacey-gammon Jul 25, 2017
a7d36dc
fix test
stacey-gammon Jul 25, 2017
d4d7b15
Merge branch 'master' of https://github.com/elastic/kibana into fix/s…
stacey-gammon Jul 25, 2017
b7870ab
Fix test errors for reals this time
stacey-gammon Jul 25, 2017
9f971e5
Merge branch 'master' of https://github.com/elastic/kibana into fix/s…
stacey-gammon Jul 27, 2017
a2e864e
Break out status and statusCode short url error tests
stacey-gammon Jul 27, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/server/http/short_url_error.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Boom from 'boom';

export function handleShortUrlError(err) {
if (err.isBoom) return err;
if (err.status === 401) return Boom.unauthorized();
if (err.status === 403) return Boom.forbidden();
if (err.status === 404) return Boom.notFound();
return Boom.badImplementation();
export function handleShortUrlError(error) {
if (!error.isBoom && !(error instanceof Error)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should not support non-errors here. Pretty sure this was spurred by the tests failing because they aren't sending real errors, which means that this code isn't actually testing what would happen in production with this condition. I think this check should go, we should always use Boom.wrap() and the tests should use real error objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, I was just worried about changing implementation details, not knowing if I would create a subtle bug somewhere.

return Boom.create(error.status || 500);
}
return Boom.wrap(error, error.status || 500);
}
10 changes: 3 additions & 7 deletions src/server/http/short_url_lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@ export default function (server) {
},

async getUrl(id, req) {
try {
const doc = await req.getSavedObjectsClient().get('url', id);
updateMetadata(doc, req);
const doc = await req.getSavedObjectsClient().get('url', id);
updateMetadata(doc, req);

return doc.attributes.url;
} catch (err) {
return '/';
}
return doc.attributes.url;
}
};
}