Skip to content
This repository was archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Add initalArgs to error payload (#141)
Browse files Browse the repository at this point in the history
Sometimes to properly handle an error you need access to the initial
request context. This PR adds initialArgs to the error payload.

An example of when this is necessary is a single reducer that stores the
results of multiple API requests under different keys. For example:

```
a: APICall ResponseA
b: APICall ResponseB
c: APICall ResponseC
```

Under the current framework, if we handle an error in our reducer, we
don't know whether the error is tied to a, b, or c. One way to solve
this is to have a handler on the server try/catch and return an
identifier (e.g. A), but this is not always possible. If a timeout or
network error occurred, the handler on the server might not even be
invoked and therefore wouldn't have the opportunity to provide an
indentifier to the request.
  • Loading branch information
cdlewis authored and ganemone committed Nov 15, 2018
1 parent 2323f1b commit eea07ae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/__tests__/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ test('createRPCHandler failure', t => {
},
failure: e => {
t.equals(e.message, error.message);
t.deepEqual(e.initialArgs, 'transformed-args');
return 'failure';
},
},
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export function createRPCHandler({
return obj;
}, {});
delete error.stack;
error.initialArgs = args;
store.dispatch(actions && actions.failure(error));
return e;
});
Expand Down

0 comments on commit eea07ae

Please sign in to comment.