UNPKG

@chubbyts/chubbyts-decode-encode

Version:

A simple decode/encode solution for json / jsonx / url-encoded / xml / yaml.

17 lines (16 loc) 531 B
import { throwableToError } from '@chubbyts/chubbyts-throwable-to-error/dist/throwable-to-error'; import { DecodeError } from './index.js'; export const createJsonTypeDecoder = () => { return { decode: (encodedData) => { try { return JSON.parse(encodedData); } catch (e) { const error = throwableToError(e); throw new DecodeError(error.message, error.stack); } }, contentType: 'application/json', }; };