mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
# Backport This will backport the following commits from `main` to `7.17`: - [Handles non-existing objects in _copy_saved_objects API call (#158036)](https://github.com/elastic/kibana/pull/158036) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
This commit is contained in:
parent
38d9cb7263
commit
4946ce0bb0
2 changed files with 37 additions and 12 deletions
|
@ -63,6 +63,15 @@ NOTE: This cannot be used with the `overwrite` option.
|
|||
+
|
||||
NOTE: This cannot be used with the `createNewCopies` option.
|
||||
|
||||
[[spaces-api-copy-saved-objects-response-codes]]
|
||||
==== Response codes
|
||||
|
||||
`200`::
|
||||
Indicates a successful call.
|
||||
|
||||
`404`::
|
||||
Indicates that the request failed because one or more of the objects specified could not be found. A list of the unresolved objects are included in the 404 response attributes.
|
||||
|
||||
[role="child_attributes"]
|
||||
[[spaces-api-copy-saved-objects-response-body]]
|
||||
==== {api-response-body-title}
|
||||
|
|
|
@ -94,18 +94,34 @@ export function initCopyToSpacesApi(deps: ExternalRouteDeps) {
|
|||
usageStatsClient.incrementCopySavedObjects({ headers, createNewCopies, overwrite })
|
||||
);
|
||||
|
||||
const copySavedObjectsToSpaces = copySavedObjectsToSpacesFactory(
|
||||
startServices.savedObjects,
|
||||
request
|
||||
);
|
||||
const sourceSpaceId = getSpacesService().getSpaceId(request);
|
||||
const copyResponse = await copySavedObjectsToSpaces(sourceSpaceId, destinationSpaceIds, {
|
||||
objects,
|
||||
includeReferences,
|
||||
overwrite,
|
||||
createNewCopies,
|
||||
});
|
||||
return response.ok({ body: copyResponse });
|
||||
try {
|
||||
const copySavedObjectsToSpaces = copySavedObjectsToSpacesFactory(
|
||||
startServices.savedObjects,
|
||||
request
|
||||
);
|
||||
const sourceSpaceId = getSpacesService().getSpaceId(request);
|
||||
const copyResponse = await copySavedObjectsToSpaces(sourceSpaceId, destinationSpaceIds, {
|
||||
objects,
|
||||
includeReferences,
|
||||
overwrite,
|
||||
createNewCopies,
|
||||
});
|
||||
return response.ok({ body: copyResponse });
|
||||
} catch (e: any) {
|
||||
if (e.type === 'object-fetch-error' && e.attributes?.objects) {
|
||||
return response.notFound({
|
||||
body: {
|
||||
message: 'Saved objects not found',
|
||||
attributes: {
|
||||
objects: e.attributes?.objects.map((obj: SavedObjectIdentifier) => ({
|
||||
id: obj.id,
|
||||
type: obj.type,
|
||||
})),
|
||||
},
|
||||
},
|
||||
});
|
||||
} else throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue