Skip to content

Clarify interceptors execution order #7200

@codenomnom

Description

@codenomnom

Section/Content To Improve

https://github.com/codenomnom/axios-interceptors-docs/blob/v1.x/README.md#interceptors


Summary

The current documentation does not clearly explain that request interceptors execute in reverse order (LIFO) while response interceptors execute in the order they were added (FIFO). I find this utterly critical to inform, as it took me quite a while to debug a dynamically added interceptors in production 😅

I've researched this and came to the conclusion this is intended behavior.
The implementation in lib/core/Axios.js (lines ~130-140) explicitly uses different array methods for the two types of interceptors:

  • Request interceptors: Use unshift() → LIFO (Last In, First Out / reverse order)
  • Response interceptors: Use push() → FIFO (First In, First Out / normal order)

The test suite even includes a comment acknowledging this behavior (source: test/specs/interceptors.spec.js):

/* request interceptors have a reversed execution order */

Suggested Improvement

I'm preparing a PR to:

  1. Add a clear "Execution Order" subsection to the Interceptors documentation
  2. Include code examples showing the exact execution flow

Relevant File(s)

README.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions