This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[server/uiSettings+shortUrl] surface errors from es
- Loading branch information
spalger
committed
Nov 23, 2016
1 parent
8d003a1
commit 9c9b551
Showing
17 changed files
with
345 additions
and
252 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
src/core_plugins/elasticsearch/lib/__tests__/get_basic_auth_realm.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import _ from 'lodash'; | ||
import Promise from 'bluebird'; | ||
import Boom from 'boom'; | ||
import getBasicAuthRealm from './get_basic_auth_realm'; | ||
import toPath from 'lodash/internal/toPath'; | ||
import filterHeaders from './filter_headers'; | ||
|
||
module.exports = (server, client) => { | ||
return (req, endpoint, params = {}) => { | ||
return (req, endpoint, clientParams = {}, options = {}) => { | ||
const wrap401Errors = options.wrap401Errors !== false; | ||
const filteredHeaders = filterHeaders(req.headers, server.config().get('elasticsearch.requestHeadersWhitelist')); | ||
_.set(params, 'headers', filteredHeaders); | ||
_.set(clientParams, 'headers', filteredHeaders); | ||
const path = toPath(endpoint); | ||
const api = _.get(client, path); | ||
let apiContext = _.get(client, path.slice(0, -1)); | ||
if (_.isEmpty(apiContext)) { | ||
apiContext = client; | ||
} | ||
if (!api) throw new Error(`callWithRequest called with an invalid endpoint: ${endpoint}`); | ||
return api.call(apiContext, params) | ||
return api.call(apiContext, clientParams) | ||
.catch((err) => { | ||
if (err.status === 401) { | ||
// TODO: The err.message is temporary until we have support for getting headers in the client. | ||
// Once we have that, we should be able to pass the contents of the WWW-Authenticate head to getRealm | ||
const realm = getBasicAuthRealm(err.message) || 'Authorization Required'; | ||
const options = { realm: realm }; | ||
return Promise.reject(Boom.unauthorized('Unauthorized', 'Basic', options)); | ||
if (!wrap401Errors || err.statusCode !== 401) { | ||
return Promise.reject(err); | ||
} | ||
return Promise.reject(err); | ||
|
||
const boomError = Boom.wrap(err, err.statusCode); | ||
const wwwAuthHeader = _.get(err, 'body.error.header[WWW-Authenticate]'); | ||
boomError.output.headers['WWW-Authenticate'] = wwwAuthHeader || 'Basic realm="Authorization Required"'; | ||
throw boomError; | ||
}); | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Boom from 'boom'; | ||
import expect from 'expect.js'; | ||
import _ from 'lodash'; | ||
import { handleShortUrlError } from '../short_url_error'; | ||
|
||
describe('handleShortUrlError()', () => { | ||
const caughtErrors = [{ | ||
status: 401 | ||
}, { | ||
status: 403 | ||
}, { | ||
status: 404 | ||
}]; | ||
|
||
const uncaughtErrors = [{ | ||
status: null | ||
}, { | ||
status: 500 | ||
}]; | ||
|
||
caughtErrors.forEach((err) => { | ||
it(`should handle ${err.status} errors`, function () { | ||
expect(_.get(handleShortUrlError(err), 'output.statusCode')).to.be(err.status); | ||
}); | ||
}); | ||
|
||
uncaughtErrors.forEach((err) => { | ||
it(`should not handle unknown errors`, function () { | ||
expect(_.get(handleShortUrlError(err), 'output.statusCode')).to.be(500); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.