[bug] don't convert KbnServerErrors again (#106220)

* don't convert KbnServerErrors again

* Add test

* fixy fix
This commit is contained in:
Liza Katz 2021-07-20 16:33:02 +02:00 committed by GitHub
parent 34c17afdd5
commit 620eaf2f6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View file

@ -11,7 +11,7 @@ import { IRouter } from 'kibana/server';
import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { getRequestAbortedSignal } from '../lib';
import { getKbnServerError } from '../../../kibana_utils/server';
import { getKbnServerError, reportServerError } from '../../../kibana_utils/server';
import type { ConfigSchema } from '../../config';
import { termsEnumSuggestions } from './terms_enum';
import { termsAggSuggestions } from './terms_agg';
@ -65,7 +65,8 @@ export function registerValueSuggestionsRoute(router: IRouter, config$: Observab
);
return response.ok({ body });
} catch (e) {
throw getKbnServerError(e);
const kbnErr = getKbnServerError(e);
return reportServerError(response, kbnErr);
}
}
);

View file

@ -24,6 +24,7 @@ export class KbnServerError extends KbnError {
* @returns `KbnServerError`
*/
export function getKbnServerError(e: Error) {
if (e instanceof KbnServerError) return e;
return new KbnServerError(
e.message ?? 'Unknown error',
e instanceof ResponseError ? e.statusCode : 500,

View file

@ -44,5 +44,14 @@ export default function ({ getService }) {
query: 'nes',
})
.expect(200, ['nestedValue']));
it('should return 404 if index is not found', () =>
supertest
.post('/api/kibana/suggestions/values/not_found')
.send({
field: 'baz.keyword',
query: '1',
})
.expect(404));
});
}