Code Monkey home page Code Monkey logo

async-catch-loader's Introduction

async-catch-loader

English | 中文

A webpack loader that can automatically injects try/catch into async function

In development, async/await asynchronous programming is often used, and try/catch is frequently used to catch asynchronous errors, which makes the business code full of try/catch very redundant.

Using this loader, you can only automatically inject try/catch into the packaged code. Makes the business code very simple

async function func() {
    let res = await new Promise(resolve => {
        setTimeout(() => {
            resolve('success')
        }, 3000)
    })
}

try/catch is automatically injected after packaging

async function func() {
    try {
       let res = await new Promise(resolve => {
            setTimeout(() => {
                resolve('success');
            }, 3000);
        });
    } catch (e) {
    //...
    }
}

Install

npm i async-catch-loader -D

Usage

// webpack.config.js
module: {
    rules: [
        {
            test: /\.js$/,
            use:{
                loader:'async-catch-loader',
                options:{
                    catchCode:`alert(e)`
                }
            }
        }
    ]
}

Options

Name Type Default Description
identifier {string} "e" The error object identifier in the catch clause
catchCode {string} "console.error(e)" Code snippet in the catch clause
finallyCode {string} undefined The code snippet in the finally clause

async-catch-loader's People

Contributors

dependabot[bot] avatar yeyan1996 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

async-catch-loader's Issues

怎么用自定义的alert?

用alert(e)这种方式肯定不符合现在页面的弹框要求,问下可以用自定义的alert么?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.