@dadi/format-error

    1.7.0 • Public • Published

    DADI Error Formatter

    Create JSON error objects for DADI applications

    npm (scoped) coverage JavaScript Style Guide semantic-release

    Overview

    format-error is designed to streamline the process of creating errors to be returned from a DADI product.

    Install

    npm install @dadi/format-error
    

    Usage

    createApiError(code, params)

    const formatError = require('@dadi/format-error')
    let error = formatError.createApiError('0001', { field: 'publicationDate' })
    {
      "code": "API-0001",
      "title": "Missing Index Key",
      "details": "'publicationDate' is specified as the primary sort field, but is missing from the index key collection.",
      "docLink": "http://docs.dadi.tech/errors/api/API-0001"
    }

    createError(product, code, params, codes)

    const formatError = require('@dadi/format-error')
    const codes = {
      "0001": {
        "code": "API-0001",
        "title": "Missing Index Key",
        "details": "'${field}' is specified as the primary sort field, but is missing from the index key collection.",
        "params": ["field"]
      },
      "0002": {
        "code": "API-0002",
        "title": "Hook Error",
        "details": "${hookName} - ${errorMessage}",
        "params": ["hookName", "errorMessage"]
      }
    }
     
    let error = formatError.createError('api', '0001', { field: 'publicationDate' }, codes)

    Keywords

    none

    Install

    npm i @dadi/format-error

    DownloadsWeekly Downloads

    24

    Version

    1.7.0

    License

    MIT

    Unpacked Size

    13.6 kB

    Total Files

    9

    Last publish

    Collaborators

    • jeanluc.thiebaut
    • josephdenne
    • jimlambie
    • arthurmingard
    • eduardoboucas
    • abovedave
    • adamkdean