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 🙏

© 2025 – Pkg Stats / Ryan Hefner

wepy-trycatch

v0.1.3

Published

a wepy lib for catch runtime error power by decorator

Readme

wepy-trycatch

a wepy lib for catch runtime error power by decorator 🔥优雅捕获wepy全局异常

特点

  • 告别代码裸奔 or 手动try catch 💥

使用方式

app.wpy

  • compsName: 捕获错误后调用的组件名
  • methodName: 捕获错误后调用组件的方法名
  • options
    • btnMsg: 按钮文案(本库不作处理,仅传递)
    • msg: 提示文案(本库不作处理,仅传递)
    • callback: 报错页面的回调函数名(本库不作处理,仅传递)
  • hook:
    • 入参: 错误信息error、传递的options
    • 用处: 将错误信息转为错误码......
  constructor(){
    super()
    wepy.$error = {
      compsName: 'ErrorModal',
      methodName: 'show',
      options: {
        btnMsg: '重新加载',
        msg: '连接服务器失败',
        callback: 'errHandler'
      },
      // 适用场景:将报错信息转成code
      hook: (error, options) => {
        if (error.includes('timeout')) {
          return {...options, msg: '连接服务器失败(1001)'}
        }
        return options
      }
    }
  }

page.wpy

  • @trycatch中不传对象时: 使用app.wpy中配置的wepy.$error参数、回调函数名
  • @trycatch中传对象时: 使用传入的参数和当前页回调函数名
  <template>
    <ErrorModal />
  </template>
  
  </script>
  import ErrorModal from '@/comps/ErrorModal'
  
  @trycatch({
    options: {
      btnMsg: '本页面生效按钮',
      msg: '本页面生效文案',
      callback: 'specialCb'
    }
  })
  export default class Test extends wepy.page {
  
    // 回调函数
    errHandler() {}
    
    // 自定义回调
    specialCb() {}
    
    // 未定义wepy.$error时,可在onErrored中取到错误信息并自行处理
    onErrored(error) {}
  }
  </script>

ErrorModal.wpy

  <script>
    export default class ErrorModal extends wepy.component {
      data = {
        errInfo: {
          msg: '报错了,失去联系.',
          btnMsg: '重新登录',
          show: false
        }
      }

      methods = {
        show(errInfo) {
          this.errInfo = {...errInfo, show: true}
        },
        close() {
          this.errInfo = {...this.errInfo, show: false}
          if ( this.errInfo.callback && 
            typeof this.$parent[errInfo.callback] === 'function'
          ) {
            // 执行报错页面的回调并结束整个报错流程
            this.$parent[this.errInfo.callback]()
          }
        }
      }
    }
  </script>