UNPKG

@typed/http

Version:

HTTP requests for node and browsers

10 lines (8 loc) 301 B
import { chain, Either, tryCatch } from '@typed/either' import { HttpResponse } from './types' export function toJson<A = unknown>(response: Either<Error, HttpResponse<A>>): Either<Error, A> { return chain( ({ responseText }) => tryCatch<A>(() => JSON.parse(responseText)), response, ) }