import req from './../../../fetch'; import { undocumentedResponse, paramsToString } from './../../../utils'; import { AllAPIResponses, CarbonError } from './../../../index'; type Params = { id: number; key: string; }; type QueryParams = { channelName: string; nodeId: number; parentNodeId?: number; timestamp?: string; value: any; }; const put = async ( params: Params, queryParams: QueryParams, headers?: Headers ): Promise> => { const resp = await req.put( `/api/lambdas/${params.id}/test${paramsToString(queryParams)}`, '', headers ); try { const clone = resp.clone(); switch (resp.status) { case 200: return { data: {}, response: clone, }; case 304: return { error: new Error('Not modified'), 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 put;