Skip to content

Commit

Permalink
fix: πŸ› correctly create error on no_matching_indices (#61257)
Browse files Browse the repository at this point in the history
* fix: πŸ› correctly create error on no_matching_indices

* feat: 🎸 improve error type checking

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
streamich and elasticmachine committed Apr 7, 2020
1 parent 3a9e7be commit afb8d8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class IndexPatternsApiClient {
query,
})
.catch((resp: any) => {
if (resp.body.statusCode === 404 && resp.body.statuscode === 'no_matching_indices') {
if (resp.body.statusCode === 404 && resp.body.attributes?.code === 'no_matching_indices') {
throw new IndexPatternMissingIndices(resp.body.message);
}

Expand Down
17 changes: 16 additions & 1 deletion src/plugins/data/server/index_patterns/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,22 @@ export function registerRoutes(http: HttpServiceSetup) {
},
});
} catch (error) {
return response.notFound();
if (
typeof error === 'object' &&
!!error?.isBoom &&
!!error?.output?.payload &&
typeof error?.output?.payload === 'object'
) {
const payload = error?.output?.payload;
return response.notFound({
body: {
message: payload.message,
attributes: payload,
},
});
} else {
return response.notFound();
}
}
}
);
Expand Down

0 comments on commit afb8d8d

Please sign in to comment.