Skip to content

Missing example for handling request timeouts in async/await syntax #7225

@mahdiehanjomshoae

Description

@mahdiehanjomshoae

Describe the bug

Describe the improvement The Axios documentation does not include a
clear example showing how to handle request timeouts using async/await
syntax.

Current behavior Timeout configuration is documented, but there is no
example demonstrating how to properly catch timeout errors using
async/await.

Expected improvement Add a simple example to the documentation, such as:

try {
  const response = await axios.get('/api/data', { timeout: 2000 });
  console.log(response.data);
} catch (error) {
  if (error.code === 'ECONNABORTED') {
    console.error('Request timed out');
  } else {
    console.error(error);
  }
}

Why this matters Handling request timeouts is a common use case,
especially in slow networks. A clear example would improve developer
experience and reduce confusion for beginners.

Environment N/A

Additional context Happy to submit a PR adding this example if
maintainers approve.

To Reproduce

No response

Code snippet

Expected behavior

No response

Axios Version

No response

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

Additional context/Screenshots

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue::documentationThis issue is related to adding / updating documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions