{"id":13780971,"url":"https://github.com/thinkjs/think-trace","last_synced_at":"2025-04-12T12:52:36.377Z","repository":{"id":57377014,"uuid":"83554933","full_name":"thinkjs/think-trace","owner":"thinkjs","description":"Error trace for ThinkJS 3.x","archived":false,"fork":false,"pushed_at":"2021-07-01T00:02:06.000Z","size":196,"stargazers_count":12,"open_issues_count":0,"forks_count":5,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-10T22:04:56.767Z","etag":null,"topics":["koa2","middleware","think-middleware","thinkjs3","trace"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":false,"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/thinkjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-01T13:01:45.000Z","updated_at":"2021-11-04T05:30:11.000Z","dependencies_parsed_at":"2022-09-26T16:41:41.141Z","dependency_job_id":null,"html_url":"https://github.com/thinkjs/think-trace","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-trace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-trace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-trace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-trace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkjs","download_url":"https://codeload.github.com/thinkjs/think-trace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571622,"owners_count":21126520,"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":["koa2","middleware","think-middleware","thinkjs3","trace"],"created_at":"2024-08-03T18:01:21.663Z","updated_at":"2025-04-12T12:52:36.348Z","avatar_url":"https://github.com/thinkjs.png","language":"HTML","readme":"# think-trace\n\n[![npm](https://img.shields.io/npm/v/think-trace.svg?style=flat-square)]()\n[![Travis](https://img.shields.io/travis/thinkjs/think-trace.svg?style=flat-square)]()\n[![Coveralls](https://img.shields.io/coveralls/thinkjs/think-trace/master.svg?style=flat-square)]()\n[![David](https://img.shields.io/david/thinkjs/think-trace.svg?style=flat-square)]()\n\nthink-trace is an error handler for ThinkJS 3.x and koa2. It provides a pretty error web interface that helps you debug your web project.\n\n![](https://p1.ssl.qhimg.com/t0105986ac7dfc1c197.png)\n\n## Installation\n\n```\nnpm install think-trace\n```\n\n## How To Use\n\n\n### Koa2\n\n```js\nconst traceMiddleware = require('think-trace');\napp.use(traceMiddleware({\n  sourceMap: false,\n  error: err =\u003e console.error(err)\n}));\n```\n\n### ThinkJS3.x\n\nModify `src/config/middleware.js`:\n\n```js\nconst trace = require('think-trace');\n\nmodule.exports = [\n  {\n    handle: trace, \n    options: {\n      sourceMap: false,\n      error(err, ctx) {\n        return console.error(err);\n      }\n    }\n  }\n];\n```\n\n## Options\n\n- `sourceMap`: Whether your project has source map support, default is `true`.\n- `debug`: Whether show error detail in web, default is `true`. \n- `ctxLineNumbers`: How long you want show error line context, default is `10`.\n- `contentType`: Due to think-trace can't get content-type while application throw error, you should set content type by yourself by this parameter. Default value is `ctx =\u003e 'html';`. You can set json content type like this:\n    ```js\n    {\n      contentType(ctx) {\n        // All request url starts of /api or request header contains `X-Requested-With: XMLHttpRequest` will output json error\n        const APIRequest = /^\\/api/.test(ctx.request.path);\n        const AJAXRequest = ctx.is('X-Requested-With', 'XMLHttpRequest');\n        \n        return APIRequest || AJAXRequest ? 'json' : 'html';\n      }\n    }\n    ```\n- `error`: callback function when catch error, it receives Error object  and ctx as parameter.\n- `templates`: error status template path, if you want to specific. You can set `templates` as a path string, then module will read all status file named like `404.html`, `502.html` as your customed status page. Or you can set `templates` as an object, for example:\n    ```js\n    {\n      options: {\n        //basic set as string, then put 404.html, 500.html into error folder\n        templates: path.join(__dirname, 'error'),\n\n        //customed set as object\n        templates: {\n          404: path.join(__dirname, 'error/404.html'),\n          500: path.join(__dirname, 'error/500.html'),\n          502: path.join(__dirname, 'error/502.html')\n        }\n      }\n    }\n    ```\n  Also you can set templates as function, function should return error template file path or error template file path object.\n\n## Contributing\n\nContributions welcome!\n\n## License\n\n[MIT](https://github.com/thinkjs/think-trace/blob/master/LICENSE)\n","funding_links":[],"categories":["Middlewares"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-trace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkjs%2Fthink-trace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-trace/lists"}