RSS

Promises rejection (..but with style)

16 May

I find handy define this kind of function in my code:

function if_error(reject, err) {
  if (err) {
    console.error(err);
    reject(err);
  }
}

Now when I’ll need to handle a rejection, my code will be

something.can('go-wrong', (err) => {
  if_error(reject, err);
  ...

It’s something between pure functional programming and very readable code.

Advertisements
 
Leave a comment

Posted by on 2017/05/16 in dev

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: