{"id":18256886,"url":"https://github.com/mediacomem/enrich-api-error","last_synced_at":"2025-04-08T22:29:00.411Z","repository":{"id":57225588,"uuid":"112318385","full_name":"MediaComem/enrich-api-error","owner":"MediaComem","description":"Add an API's HTTP response to an error's stack trace for debugging.","archived":false,"fork":false,"pushed_at":"2017-11-30T08:32:37.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-17T18:35:51.852Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MediaComem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-28T10:02:15.000Z","updated_at":"2017-11-28T10:04:32.000Z","dependencies_parsed_at":"2022-08-24T11:00:27.078Z","dependency_job_id":null,"html_url":"https://github.com/MediaComem/enrich-api-error","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fenrich-api-error","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fenrich-api-error/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fenrich-api-error/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fenrich-api-error/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MediaComem","download_url":"https://codeload.github.com/MediaComem/enrich-api-error/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247938558,"owners_count":21021548,"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-11-05T10:24:01.655Z","updated_at":"2025-04-08T22:29:00.387Z","avatar_url":"https://github.com/MediaComem.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# enrich-api-error\n\nAdd an API's HTTP response to an error's stack trace for debugging.\n\n[![npm version](https://badge.fury.io/js/enrich-api-error.svg)](https://badge.fury.io/js/enrich-api-error)\n[![Dependency Status](https://gemnasium.com/badges/github.com/MediaComem/enrich-api-error.svg)](https://gemnasium.com/github.com/MediaComem/enrich-api-error)\n[![Build Status](https://travis-ci.org/MediaComem/enrich-api-error.svg?branch=master)](https://travis-ci.org/MediaComem/enrich-api-error)\n[![Coverage Status](https://coveralls.io/repos/github/MediaComem/enrich-api-error/badge.svg?branch=master)](https://coveralls.io/github/MediaComem/enrich-api-error?branch=master)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.txt)\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\nDeveloped at the [Media Engineering Institute](http://mei.heig-vd.ch) ([HEIG-VD](https://heig-vd.ch)).\n\n\n\n## Usage\n\nThis is a low-level utility developed as a dependency to [mocha-api-errors](https://github.com/MediaComem/mocha-api-errors).\n\nIt's not meant to be used directly, but here's an example using [supertest](https://github.com/visionmedia/supertest) in a [Mocha](https://mochajs.org) test:\n\n```js\nconst enrichApiError = require('enrich-api-error');\nconst supertest = require('supertest');\n\nconst app = require('./my-express-app');\n\ndescribe('enrich-api-error', () =\u003e {\n  it('should add the HTTP response to a stack trace', async () =\u003e {\n\n    const res = await supertest(app).get('/test');\n\n    if (res.status != 200) {\n      throw enrichApiError(new Error(`Expected status code to be 200, got ${res.status}`), res);\n    }\n  });\n});\n\n// This is an example of the output you could get with a mocha test.\n// Note the HTTP response description that has been inserted before\n// the error's stack trace:\n//\n//  something\n//    1) should work\n//\n//  0 passing (50ms)\n//  1 failing\n//\n//  1) something\n//       should work:\n//\n//      Error: Expected status code to be 200, got 400\n//\n//      HTTP/1.1 400 Bad Request\n//      x-powered-by: Express\n//      content-type: application/json; charset=utf-8\n//      content-length: 13\n//      etag: W/\"d-pedE0BZFQNM7HX6mFsKPL6l+dUo\"\n//      date: Tue, 28 Nov 2017 08:58:02 GMT\n//      connection: close\n//\n//      {\n//        \"foo\": \"bar\"\n//      }\n//\n//      at Context.\u003canonymous\u003e (spec/index.spec.js:20:21)\n//      at \u003canonymous\u003e\n//      at process._tickCallback (internal/process/next_tick.js:188:7)\n```\n\n**enrich-api-error** expects the response body to be available as the `body` or\n`text` property of the response object.  (This is usually provided by Node.js\nHTTP libraries such as request or supertest.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediacomem%2Fenrich-api-error","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmediacomem%2Fenrich-api-error","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediacomem%2Fenrich-api-error/lists"}