UNPKG

@thisismissem/adonisjs-respond-with

Version:

A small plugin for Adonis.js to make responding with different content-types easier.

21 lines (20 loc) 776 B
import { InvalidArgumentsException } from '@adonisjs/core/exceptions'; /** * Define the config for respondWith */ export function defineConfig(config) { if (Object.hasOwnProperty.call(config, 'mappings')) { if (typeof config.mappings !== 'object' || Array.isArray(config.mappings)) { throw new InvalidArgumentsException('The "mappings" property must be an object if defined'); } if (Object.hasOwnProperty.call(config.mappings, 'error')) { throw new InvalidArgumentsException('The "mappings" property cannot contain "error" as a key, as this is a reserved type'); } } return { defaultHandler: config.defaultHandler ?? 'error', mappings: { ...config.mappings, }, }; }