import req from './../../../fetch'; import { paramsToString, undocumentedResponse } from './../../../utils'; import { AllAPIResponses, CarbonError } from './../../../index'; type Params = { folderId?: number; nodeId?: Array; uniqueId?: Array; }; type AlarmsSuccess = { nodeId: Array<{ ruleId: number; traceId: string; updatedAt: string; }>; }; const get = async ( params: Params, headers?: Headers ): Promise> => { try { const resp = await req.get( `/api/alarms/current${paramsToString(params)}`, headers ); const clone = resp.clone(); switch (resp.status) { case 200: return { data: (await resp.json()) as AlarmsSuccess, response: clone, }; case 400: case 401: case 403: case 404: case 500: return { error: (await resp.json()) as CarbonError, response: clone, }; default: return { error: new Error(undocumentedResponse(resp)), response: clone, }; } } catch (e) { return { error: e, response: undefined }; } }; export default get;