UNPKG

@datalayer/core

Version:

[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.io)

45 lines (44 loc) 1.51 kB
/* * Copyright (c) 2023-2025 Datalayer, Inc. * Distributed under the terms of the Modified BSD License. */ /** * Health check API functions for the Datalayer Spacer service. * * Provides functions for checking the health status of the Spacer service. * * @module api/spacer/healthz */ import { requestDatalayerAPI } from '../DatalayerApi'; import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants'; /** * Health check ping endpoint for Spacer service * @param baseUrl - Base URL for the API (defaults to production Spacer URL) * @returns Health check response * @throws {Error} If the health check fails * * @remarks * This endpoint provides a basic health check for the Spacer service. * It returns the current status of the service. * * Expected status codes: * - 200: Service is healthy */ export const ping = async (baseUrl = DEFAULT_SERVICE_URLS.SPACER) => { try { const response = await requestDatalayerAPI({ url: `${baseUrl}${API_BASE_PATHS.SPACER}/ping`, method: 'GET', }); return response; } catch (error) { // Check if it's a response error with status code information if (error.response) { const status = error.response.status; throw new Error(`Health check failed: Service unhealthy (status ${status}) - ${error.message}`); } // Re-throw other errors (network errors, etc.) throw new Error(`Health check failed: ${error.message}`); } };