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

Add initalArgs to error payload #141

Merged
merged 1 commit into from
Nov 15, 2018

Conversation

cdlewis
Copy link
Contributor

@cdlewis cdlewis commented Nov 13, 2018

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.

Another way of handling this would be for us to write our own
thunk-style handler for RPCs, but this seems against the spirit of
Fusion.

By exposing initialArgs, we can do:

{
  start: (state, action) => ({
    ...state,
    [action.payload.requestId]: {error: false},
  }),
  failure: (state, action) => ({
    [action.payload.initialArgs.requestId]: {error: true},
  }),
}

Incidentally, this partially fixes #136.

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.

Another way of handling this would be for us to write our own
thunk-style handler for RPCs, but this seems against the spirit of
Fusion.
@CLAassistant
Copy link

CLAassistant commented Nov 13, 2018

CLA assistant check
All committers have signed the CLA.

@trevorwhealy
Copy link

It would also be very helpful to have the initial argument request context on the success handler too.

@cdlewis
Copy link
Contributor Author

cdlewis commented Nov 15, 2018

I agree adding it to success would be useful. I think that's little more tricky because the result doesn't necessarily have to be an object.

@ganemone ganemone merged commit eea07ae into fusionjs:master Nov 15, 2018
@AlexMSmithCA AlexMSmithCA mentioned this pull request Nov 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] pass args to both success + failure reducer handlers
5 participants