feat(search): improve router query errors
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-search-backend': patch
|
||||
---
|
||||
|
||||
Change the router's response to include the error message instead of its object type in case it fails during a search query because the messages have more info.
|
||||
@@ -74,6 +74,23 @@ describe('createRouter', () => {
|
||||
});
|
||||
|
||||
describe('GET /query', () => {
|
||||
it('throws meaningful query errors', async () => {
|
||||
const error = new Error('Query error message');
|
||||
mockSearchEngine.query.mockRejectedValueOnce(error);
|
||||
|
||||
const response = await request(app).get('/query');
|
||||
|
||||
expect(response.status).toEqual(500);
|
||||
expect(response.body).toMatchObject(
|
||||
expect.objectContaining({
|
||||
error: {
|
||||
name: 'Error',
|
||||
message: `There was a problem performing the search query: ${error.message}`,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('returns empty results array', async () => {
|
||||
const response = await request(app).get('/query');
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ export async function createRouter(
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`There was a problem performing the search query. ${error}`,
|
||||
`There was a problem performing the search query: ${error.message}`,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user