Skip to content

bug: POST /api/v1/quote returns plain text error for invalid token address #4440

@ChainsQueen

Description

@ChainsQueen

Problem

Sending an invalid token address returns a plain text error
message instead of structured JSON.

Impact

Low — does not block core functionality but causes SDK
clients and integrators to fail when parsing error responses
as they expect JSON on all responses from this endpoint.

To reproduce

  1. POST https://api.cow.fi/sepolia/api/v1/quote
  2. Header: Content-Type: application/json
  3. Body:
    {
    "sellToken": "not-an-address",
    "buyToken": "0x0625aFB445C3B6B7B929342a04A22599fd5dBB59",
    "sellAmountBeforeFee": "1000000000000000000",
    "kind": "sell",
    "from": "0x0000000000000000000000000000000000000001"
    }

Expected behaviour

Status: 422
Content-Type: application/json
Body: { "errorType": "...", "description": "..." }

Screenshots/logs

See attached Postman screenshot showing the plain text
422 response for invalid token address request.

Image Image Image

services version/commit hash and environment

Version: v2.362.3-dirty
Environment: production (https://api.cow.fi/sepolia)

Additional context

The plain text response appears to be Axum's default
JsonRejection behaviour which is not overridden here.
Reference: https://docs.rs/axum/latest/axum/extract/index.html

Actual response received:
Status: 422 Unprocessable Entity (WebDAV) (RFC 4918)
Content-Type: text/plain; charset=utf-8
Body: Failed to deserialize the JSON body into the target
type: sellToken: invalid string length at line 2 column 31

Additional reproduction scenarios with the same behaviour:

Zero sell amount:
Request body:
{
"sellToken": "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",
"buyToken": "0x0625aFB445C3B6B7B929342a04A22599fd5dBB59",
"sellAmountBeforeFee": "0",
"kind": "sell",
"from": "0x0000000000000000000000000000000000000001"
}
Status: 422 Unprocessable Entity (WebDAV) (RFC 4918)
Content-Type: text/plain; charset=utf-8
Body: Failed to deserialize the JSON body into the target
type: data did not match any variant of untagged enum
SellAmount at line 7 column 1

Missing buy token:
Request body:
{
"sellToken": "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",
"sellAmountBeforeFee": "1000000000000000000",
"kind": "sell",
"from": "0x0000000000000000000000000000000000000001"
}
Status: 422 Unprocessable Entity (WebDAV) (RFC 4918)
Content-Type: text/plain; charset=utf-8
Body: Failed to deserialize the JSON body into the target
type: missing field buyToken at line 6 column 1

** Negative sell amount:**
Request body:
{
"sellToken": "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",
"buyToken": "0x0625aFB445C3B6B7B929342a04A22599fd5dBB59",
"sellAmountBeforeFee": "-1000000000000000000",
"kind": "sell",
"from": "0x0000000000000000000000000000000000000001"
}
Status: 422 Unprocessable Entity (WebDAV) (RFC 4918)
Content-Type: text/plain; charset=utf-8
Body: Failed to deserialize the JSON body into the target
type: data did not match any variant of untagged enum
SellAmount at line 7 column 1

Very long token address:
Request body:
{
"sellToken": "0xAAAA...(500 chars)",
"buyToken": "0x0625aFB445C3B6B7B929342a04A22599fd5dBB59",
"sellAmountBeforeFee": "1000000000000000000",
"kind": "sell",
"from": "0x0000000000000000000000000000000000000001"
}
Status: 422 Unprocessable Entity (WebDAV) (RFC 4918)
Content-Type: text/plain; charset=utf-8
Body: Failed to deserialize the JSON body into the target
type: sellToken: invalid string length at line 2 column 567

All scenarios confirm the same root cause — Axum default
JsonRejection behaviour returning plain text instead of
structured JSON.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtrack:maintenancemaintenance track

    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