Netflix / falcor

A JavaScript library for efficient data fetching
http://netflix.github.io/falcor
Apache License 2.0
10.49k stars 446 forks source link

Error propagation in `call` routes #745

Open jrwells opened 8 years ago

jrwells commented 8 years ago

In our scaffolding library (https://github.com/ParabolInc/falcor-saddle), we create a call route for record creation using a set of promises, a createPromise and a getLengthPromise. In our unit tests createPromise is purposefully throwing an error. This error seems to be incorrectly propagated up to Falcor and back to the client; it actually causes falcor-http-datasource to throw Error: {"throwToNext":true}.

const createPromise = async function (params) {
    throw new Error('PromiseError');
}

export function createCallCreateRoute(routeBasename, acceptedKeys,
  createPromise, getLengthPromise,
  modelIdGetter = defModelIdGetter) {
  const routeByIdBasename = routeBasename + routeSuffixById;
  return {
    route: routeBasename + '.' + routeSuffixCreate,
    async call(callPath, args) {
      const objParams = _.pick(args[0], acceptedKeys);
      try {
        const newObj = await createPromise(objParams);
        const newLength = await getLengthPromise();

        return [
          jsonGraph.pathValue(
            [routeBasename, newLength - 1],
            jsonGraph.ref([ routeByIdBasename, modelIdGetter(newObj) ])
          ),
          jsonGraph.pathValue([ routeBasename, routeSuffixLength ], newLength)
        ];
      } catch (err) {
        throw new Error(err);
      }
    }
  };
}

The PromiseError is correctly propagated from the call function (after the catch), but it does not reach the client.

synhaptein commented 8 years ago

Is there any progress regarding this issue? Should it behaves like get/set and should it be catch by the errorSelector callback on the model?

gottfrois commented 8 years ago

I actually hit the same issue where the error is not propagated to the client.