[bug] don't convert KbnServerErrors again (#106220)
* don't convert KbnServerErrors again * Add test * fixy fix
This commit is contained in:
parent
34c17afdd5
commit
620eaf2f6a
3 changed files with 13 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue