[8.10] [Security Solution] ensure fleetfilenotfound is reported as a 404 (#164738) (#164836)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Security Solution] ensure fleetfilenotfound is reported as a 404
(#164738)](https://github.com/elastic/kibana/pull/164738)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Dan
Panzarella","email":"pzl@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-08-24T19:48:10Z","message":"[Security
Solution] ensure fleetfilenotfound is reported as a 404
(#164738)","sha":"9e89a9694b9bacc275f8d2125200b53447a13f1f","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Defend
Workflows","v8.10.0","v8.11.0"],"number":164738,"url":"https://github.com/elastic/kibana/pull/164738","mergeCommit":{"message":"[Security
Solution] ensure fleetfilenotfound is reported as a 404
(#164738)","sha":"9e89a9694b9bacc275f8d2125200b53447a13f1f"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/164738","number":164738,"mergeCommit":{"message":"[Security
Solution] ensure fleetfilenotfound is reported as a 404
(#164738)","sha":"9e89a9694b9bacc275f8d2125200b53447a13f1f"}}]}]
BACKPORT-->

Co-authored-by: Dan Panzarella <pzl@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Ashokaditya 2023-08-25 19:40:30 +02:00 committed by GitHub
parent 90529f8fb8
commit 63d021f7d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@
*/
import type { IKibanaResponse, KibanaResponseFactory, Logger } from '@kbn/core/server';
import { FleetFileNotFound } from '@kbn/fleet-plugin/server/errors';
import { CustomHttpRequestError } from '../../utils/custom_http_request_error';
import { NotFoundError } from '../errors';
import { EndpointHostUnEnrolledError, EndpointHostNotFoundError } from '../services/metadata';
@ -38,7 +39,7 @@ export const errorHandler = <E extends Error>(
});
}
if (error instanceof NotFoundError) {
if (error instanceof NotFoundError || error instanceof FleetFileNotFound) {
return res.notFound({ body: error });
}