Skip to content

Instantly share code, notes, and snippets.

View olehcambel's full-sized avatar
🐍

Олег Моисеенко olehcambel

🐍
  • @[object Object]
  • Kyiv
View GitHub Profile
@olehcambel
olehcambel / controller1.js
Last active January 3, 2019 16:03
How to handle async errors?
const app = require('express')();
const getConvert = async (req, res, next) => {
try {
throw 'err';
} catch (err) {
next(err)
}
};
@olehcambel
olehcambel / fetch
Created November 28, 2018 08:09
promise \ callback => async \ await
const fetch = () => {
return new Promise((resolve, reject) => {
this.validate('name')
.then(result => {
return resolve(result.id)
})
.catch(reject)
})
}
@olehcambel
olehcambel / async-parallel.js
Created November 6, 2018 18:03
Promise.all with catch
module.exports = async (items, callback) => {
const errors = [];
const promises = [];
try {
if (!items && !Array.isArray(items))
throw `type 'items ${items}' should be Array`;
items.forEach(item => {
promises.push(callback(item).catch(err => errors.push(err)));