{"id":22799997,"url":"https://github.com/dadi/format-error","last_synced_at":"2025-04-30T19:33:47.280Z","repository":{"id":57105405,"uuid":"69847883","full_name":"dadi/format-error","owner":"dadi","description":"Create JSON error objects for DADI applications","archived":false,"fork":false,"pushed_at":"2019-05-03T15:00:04.000Z","size":122,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-04-25T23:22:35.889Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dadi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-03T07:01:34.000Z","updated_at":"2019-05-03T15:00:03.000Z","dependencies_parsed_at":"2022-08-20T23:50:10.272Z","dependency_job_id":null,"html_url":"https://github.com/dadi/format-error","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadi%2Fformat-error","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadi%2Fformat-error/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadi%2Fformat-error/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadi%2Fformat-error/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dadi","download_url":"https://codeload.github.com/dadi/format-error/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246365644,"owners_count":20765549,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-12T07:10:45.478Z","updated_at":"2025-03-30T19:17:39.613Z","avatar_url":"https://github.com/dadi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DADI Error Formatter\n\n\u003e Create JSON error objects for DADI applications\n\n[![npm (scoped)](https://img.shields.io/npm/v/@dadi/format-error.svg?maxAge=10800\u0026style=flat-square)](https://www.npmjs.com/package/@dadi/format-error)\n[![Coverage Status](https://coveralls.io/repos/github/dadi/format-error/badge.svg?branch=master)](https://coveralls.io/github/dadi/format-error?branch=master)\n[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)\n\n## Overview\n\nformat-error is designed to streamline the process of creating errors to be returned from a DADI product. \n\n## Install\n\n```\nnpm install @dadi/format-error\n```\n\n## Usage\n\n### createApiError(code, params)\n\n```js\nconst formatError = require('@dadi/format-error')\nlet error = formatError.createApiError('0001', { field: 'publicationDate' })\n```\n\n```json\n{\n  \"code\": \"API-0001\",\n  \"title\": \"Missing Index Key\",\n  \"details\": \"'publicationDate' is specified as the primary sort field, but is missing from the index key collection.\",\n  \"docLink\": \"http://docs.dadi.tech/errors/api/API-0001\"\n}\n```\n\n### createError(product, code, params, codes)\n\n```js\nconst formatError = require('@dadi/format-error')\nconst codes = {\n  \"0001\": {\n    \"code\": \"API-0001\",\n    \"title\": \"Missing Index Key\",\n    \"details\": \"'${field}' is specified as the primary sort field, but is missing from the index key collection.\",\n    \"params\": [\"field\"]\n  },\n  \"0002\": {\n    \"code\": \"API-0002\",\n    \"title\": \"Hook Error\",\n    \"details\": \"${hookName} - ${errorMessage}\",\n    \"params\": [\"hookName\", \"errorMessage\"]\n  }\n}\n\nlet error = formatError.createError('api', '0001', { field: 'publicationDate' }, codes)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdadi%2Fformat-error","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdadi%2Fformat-error","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdadi%2Fformat-error/lists"}