npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

think-trace

v1.0.18

Published

Error trace for thinkjs 3.x

Downloads

2,758

Readme

think-trace

npm Travis Coveralls David

think-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.

Installation

npm install think-trace

How To Use

Koa2

const traceMiddleware = require('think-trace');
app.use(traceMiddleware({
  sourceMap: false,
  error: err => console.error(err)
}));

ThinkJS3.x

Modify src/config/middleware.js:

const trace = require('think-trace');

module.exports = [
  {
    handle: trace, 
    options: {
      sourceMap: false,
      error(err, ctx) {
        return console.error(err);
      }
    }
  }
];

Options

  • sourceMap: Whether your project has source map support, default is true.
  • debug: Whether show error detail in web, default is true.
  • ctxLineNumbers: How long you want show error line context, default is 10.
  • 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 => 'html';. You can set json content type like this:
    {
      contentType(ctx) {
        // All request url starts of /api or request header contains `X-Requested-With: XMLHttpRequest` will output json error
        const APIRequest = /^\/api/.test(ctx.request.path);
        const AJAXRequest = ctx.is('X-Requested-With', 'XMLHttpRequest');
          
        return APIRequest || AJAXRequest ? 'json' : 'html';
      }
    }
  • error: callback function when catch error, it receives Error object and ctx as parameter.
  • 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:
    {
      options: {
        //basic set as string, then put 404.html, 500.html into error folder
        templates: path.join(__dirname, 'error'),
    
        //customed set as object
        templates: {
          404: path.join(__dirname, 'error/404.html'),
          500: path.join(__dirname, 'error/500.html'),
          502: path.join(__dirname, 'error/502.html')
        }
      }
    }
    Also you can set templates as function, function should return error template file path or error template file path object.

Contributing

Contributions welcome!

License

MIT