Code Monkey home page Code Monkey logo

Comments (5)

analog-nico avatar analog-nico commented on July 28, 2024

Hi @MichielDeMey the transform function is actually your best friend. As you see in the tests you may either return a rejected promise or throw an Error inside the transform function.

You can also pass the transform function to .defaults(...) which then hopefully meets your DRY goal.

Let me know if this solves what you need.

from request-promise.

MichielDeMey avatar MichielDeMey commented on July 28, 2024

Hey @analog-nico

This is exactly what I needed!

One minor downside is that we have to create a new Promise and reject that one instead of having a reference to the promise itself which we can reject. But I can live with that small overhead.

Now I just have to figure out the following error thrown by Request:
(This error is thrown both by using the rejected promise and throwing a new error)

Possibly unhandled Error: [error message here]

Which is discussed here: https://github.com/petkaantonov/bluebird#error-handling

from request-promise.

analog-nico avatar analog-nico commented on July 28, 2024

Great!

You may just throw the Error inside the transform function and you won't have the overhead of creating another promise.

The "Possibly unhandled Error" is printed if you don't call .catch(...) or call it too late.

from request-promise.

MichielDeMey avatar MichielDeMey commented on July 28, 2024

I've decided to just throw the Error in order to avoid the overhead of creating a new Promise.

Thanks!

from request-promise.

analog-nico avatar analog-nico commented on July 28, 2024

You are welcome!

from request-promise.

Related Issues (20)

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.