UNPKG

@hashgraph/solo

Version:

An opinionated CLI tool to deploy and manage private Hedera Networks.

38 lines 1.74 kB
import { ResourceNotFoundError } from './errors/resource_operation_errors.js'; import { StatusCodes } from 'http-status-codes'; import { KubeApiError } from './errors/kube_api_error.js'; export class KubeApiResponse { constructor() { } /** * Checks the response for an error status code and throws an error if one is found. * * @param response - the HTTP response to be verified. * @param resourceType - the type of resource being checked. * @param resourceOperation - the operation being performed on the resource. * @param namespace - the namespace of the resource being checked. * @param name - the name of the resource being checked. */ static check(response, resourceOperation, resourceType, namespace, name) { if (KubeApiResponse.isNotFound(response)) { throw new ResourceNotFoundError(resourceOperation, resourceType, namespace, name); } if (KubeApiResponse.isFailingStatus(response)) { throw new KubeApiError(`failed to ${resourceOperation} ${resourceType} '${name}' in namespace '${namespace}'`, +response?.statusCode, null, { resourceType: resourceType, resourceOperation: resourceOperation, namespace: namespace, name: name, }); } } static isFailingStatus(response) { return (+response?.statusCode || StatusCodes.INTERNAL_SERVER_ERROR) > StatusCodes.ACCEPTED; } static isNotFound(response) { return +response?.statusCode === StatusCodes.NOT_FOUND; } static isCreatedStatus(response) { return +response?.statusCode === StatusCodes.CREATED; } } //# sourceMappingURL=kube_api_response.js.map