Skip to content

[0.28.1] options.paramsSerializer as function don't work #6341

@vernou

Description

@vernou

Describe the bug

We have a custom serialize method that is passed to axios by options.paramsSerializer.
It's work fine with axios@0.28.0, but from axios@0.28.1, it throw the error :

options must be an object

To Reproduce

No response

Code snippet

const conf = {
  paramsSerializer: function (params: any) {
    return qs.stringify(params, { arrayFormat: 'repeat' })
  }
}

const instance = axios.create(conf)
instance.request()

Expected behavior

The HTTP request is executed (like in 0.28.0).

Axios Version

0.28.1

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

No response

Additional context/Screenshots

The problem come from the commit 111811eadc849c08a3a2074930c50f68afa6eba5.

In axios.js, this check was added :

if (paramsSerializer !== undefined) {
  validator.assertOptions(paramsSerializer, {
    encode: validators.function,
    serialize: validators.function
  }, true);
}

And validator.assertOptions throw the error when the first parameter isn't a object.

Moreover, the next line manage the case where paramsSerializer is a function :

utils.isFunction(paramsSerializer) && (config.paramsSerializer = {serialize: paramsSerializer});

A solution will be to down the check after the below line transform paramsSerializer from function to object, so the check will be ok.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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