Skip to content

Instantly share code, notes, and snippets.

@xgqfrms
Created May 17, 2020 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgqfrms/7313acccc6f4f35b00a253b0f8877bee to your computer and use it in GitHub Desktop.
Save xgqfrms/7313acccc6f4f35b00a253b0f8877bee to your computer and use it in GitHub Desktop.
async /await errorCaptured

async /await errorCaptured

"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2020-05-17
 * @modified
 *
 * @description async /await errorCaptured
 * @augments
 * @example
 * @link
 *
 */

const log = console.log;

async function errorCaptured(asyncFunc, placeholder = null, debug = false) {
  try {
    const asyncData = await asyncFunc();
    if(debug) {
      log(`asyncData =`, asyncData);
    }
    return [placeholder, asyncData];
  } catch (error) {
    return [error, placeholder];
  }
};

const errorCaptured = async (asyncFunc, placeholder = null, debug = false) => {
  try {
    const asyncData = await asyncFunc();
    if(debug) {
      log(`asyncData =`, asyncData);
    }
    return [placeholder, asyncData];
  } catch (error) {
    return [error, placeholder];
  }
};


export default errorCaptured;

export {
  errorCaptured,
};
@xgqfrms
Copy link
Author

xgqfrms commented May 17, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment