fix(DockerContainer): Fix getContainerById to return undefined for non-existent containers
This commit is contained in:
@@ -28,13 +28,14 @@ export class DockerContainer extends DockerResource {
|
||||
/**
|
||||
* Internal: Get a container by ID
|
||||
* Public API: Use dockerHost.getContainerById(id) instead
|
||||
* Returns undefined if container does not exist
|
||||
*/
|
||||
public static async _fromId(
|
||||
dockerHostArg: DockerHost,
|
||||
containerId: string,
|
||||
): Promise<DockerContainer> {
|
||||
const response = await dockerHostArg.request('GET', `/containers/${containerId}/json`);
|
||||
return new DockerContainer(dockerHostArg, response.body);
|
||||
): Promise<DockerContainer | undefined> {
|
||||
const containers = await this._list(dockerHostArg);
|
||||
return containers.find((container) => container.Id === containerId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user