Skip to content

don't call FETCH_SUCCESS on error #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

federicoweber
Copy link

This is needed so that in case of errors we can handle it in the FETCH_FAIL handler, without worrying about protecting the FETCH_SUCCESS logic from missing or malformed data.

This is needed to properly handle RPC errors in the front-end in https://github.com/bufferapp/buffer-analyze/pull/337

Hey @djfarrelly and @msanroman, would love your eyes on this one, not sure if I'm missing any cases where we want to triggerFETCH_SUCESS in case of errors.

This is needed so that in case of errors we can handle it in the
`FETCH_FAIL` handler, without worring about protecting the
`FETCH_SUCCESS` from missing or malformed data.

This is needed to properly handle RPC errors in the front-end in https://github.com/bufferapp/buffer-analyze/pull/337
@federicoweber
Copy link
Author

Hey @msanroman and @djfarrelly,
doing a bit more digging I think the source of the double triggered event is micro-rpc-client specifically the logic in https://github.com/bufferapp/micro-rpc-client/blob/master/index.js#L26-L50.

If I'm reading this correctly:

the first .then will always return a Promise that is correctly resolved, and this will trigger the SUCCESS event. As we are passing the error in the body the catch won't fire, unless there is a problem parsing the response.

 .then(
        response =>
          new Promise((resolve, reject) => {
            response
              .json()
              .then(parsedResponse =>
                resolve({
                  response: parsedResponse,
                  status: response.status,
                }),
              )
              .catch(error => reject(error));
          }),
      )

and the second one will find the error and trigger the FAIL event.

      .then(({ response, status }) => {
        if (response.error) {
          const err = new Error(response.error);
          err.code = response.code;
          err.handled = response.handled;
          err.status = status;
          throw err;
        }
        return response;
      })

I think it will be enought to switch the two and have the error check happen first, but I have't tested that yet.

Closing this PR, as is not really solving the root cause.

),
)
.then(result => {
console.log(result)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove this debugging line? If you find this logging useful for you, maybe add an option to the middleware like { debug: true }?

.then(result => {
console.log(result)

if (result) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, what is the response code in this case? My only question is, should this be handled in the RPCClient library and not here? If you think this should be handled higher up in the client library, that might be good to ship a change there first, but that's your call. If you want to bounce an idea around for that, I know Eduardo and Phil have thought a bunch about the RPC server side code and the client itself and we haven't iterated on the client library since Harrison wrote it last year :D

@djfarrelly
Copy link

Whoops - sorry @federicoweber, I missed your update on this before my comments 😆 - It looks like we're on the same page already! 😉 Def connect w/ Edu & Phil if you want to bounce around more ideas or are looking for reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants