redux-offline: Discard not working

I am trying to override the basic implementation of discard to write an error log as well as discard the action when the error is not a network error. My code for that is

discard: (error, _action, _retries) => {
    if (!('status' in error)) {

     // I write the error log here

      // I alert the user to let them know their action failed
      alert('An error occurred. Please retry.')
      return true
    }

    return error.status >= 400 && error.status < 500
  }

The issue I am encountering is that it meets the condition to discard the action, but it appears to be retrying constantly because the application is stuck in a never-ending loop of alerts, even though it should be discarding the action by returning true. Logging _retries evaluates to 0. Am I missing something?

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

I think I finally found it… Error was in my reducer, in this case the rollback action. I typed a comma instead of a period in a line of code, but the code still worked so it never blew up to show me the error. The reducer wasn’t working as intended, but I’m not sure why that caused the behavior I wrote about above. I will now go through all my reducers and make sure they are all working as intended.

Yes, this issue held me up a bit and I am in crunch time now, but if I get the chance I will do some testing and post the reducer and the state it returned.

I have narrowed it down to an issue with my actions. If I dispatch the following action with no payload or meta data inside commit or rollback, it discards the action correctly

export const receivePartToNewWorkOrder = () => ({
  type: "REQUEST",
  meta: {
    offline: {
      effect: {
        url: "inventory/receive_parts_order/",
        method: "POST",
        data: { foo: "bar" }
      },
      commit: {
        type: "COMMIT"
      },
      rollback: {
        type: "ROLLBACK"
      }
    }
  }
});

But if I dispatch the following action with a payload object and meta objects inside commit and rollback, discard returns true but the item never gets discarded and is retried constantly

export const receivePartToNewWorkOrder = (disp, item, position) => ({
  type: "RECEIVE_PART_TO_NEW_WORK_ORDER",
  payload: {
    disp,
    item,
    position
  },
  meta: {
    offline: {
      effect: {
        url: "inventory/receive_parts_order/",
        method: "POST",
        data: { foo: "bar" }
      },
      commit: {
        type: "RECEIVE_PART_TO_NEW_WORK_ORDER_COMMIT",
        meta: {
          disp,
          item
        }
      },
      rollback: {
        type: "RECEIVE_PART_TO_WORK_ORDER_ROLLBACK",
        meta: {
          disp,
          item
        }
      }
    }
  }
});

Would love any advice or insight into if there is any reason one works while the other doesn’t.