feat(search): improve router query errors

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2023-02-03 19:59:51 +01:00
parent 50d7039368
commit 1b30c9a0f7
3 changed files with 23 additions and 1 deletions
+5
View File
@@ -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');
+1 -1
View File
@@ -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}`,
);
}
},