Skip to content

Conversation

@dhoko
Copy link
Contributor

@dhoko dhoko commented Dec 18, 2025

👋 Hello,

When we try to upload a file to the API, it can fail for an unexpected issue -> the filename of the source we try to upload.

The API gives us this error

        "errors": [
          {
            "error": {
              "key": "Crowdin-API-FileName",
              "errors": [
                {
                  "code": "regexNotMatch",
                  "message": "File name can't contain any of the following characters: \\ / : * ? \" < > |"
                }
              ]
            }
          }
        ]

I was not expecting the API to crash on the storage step because the filepath was wrong.
I thought we uploaded a blob at this stage, and the filename of the source didn't matter. It was a random blob uploaded to get an id we could use when we assign the file later. I was wrong 🙈

I found this inside the source:

            headers["Crowdin-API-FileName"] = os.path.basename(file.name)

Sadly, the error doesn't tell us enough details, to know what we sent was wrong. The idea is to bind the source headers inside the exception so we have the data we need to understand the error, at least way faster than today 😁

it gives us:

{
  "details": {
    "crowdin": {
      "headers": {
        "Date": "Thu, 18 Dec 2025 15:32:18 GMT",
        "Content-Type": "application/json",
        "Transfer-Encoding": "chunked",
        "Connection": "keep-alive",
        "Server": "nginx",
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Methods": "GET, POST, OPTIONS, DELETE, PATCH, PUT",
        "Access-Control-Allow-Headers": "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,ETag,Accept,AcceptEncoding,Authorization,Crowdin-API-FileName,X
        -Crowdin-Integrations-User-Agent",
        "Access-Control-Allow-Credentials": "true",
        "Strict-Transport-Security": "max-age=31536000; includeSubdomains"
      },
      "source_headers": {
        "Content-Type": "application/json",
        "Crowdin-API-FileName": "source-2025-12-18_16:32.json"
      },
      "data": {
        "errors": [
          {
            "error": {
              "key": "Crowdin-API-FileName",
              "errors": [
                {
                  "code": "regexNotMatch",
                  "message": "File name can't contain any of the following characters: \\ / : * ? \" < > |"
                }
              ]
            }
          }
        ]
      },
      "http_code": 400,
      "raw": "ValidationError: http_status=400, request_id=None, detail: None, context=b'{\"errors\":[{\"error\":{\"key\":\"Crowdin-API-FileName\",\"errors\":[{\"code\":\"regexNotMatch\",
      \"message\":\"File name can\\'t contain any of the following characters: \\\\\\\\ \\\\/ : * ? \\\\\" < > |\"}]}}]}'"
    }
  }
}

Easier to debug `ValidationError` from the server as they do not provide
enough details
@codecov-commenter
Copy link

codecov-commenter commented Dec 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.35%. Comparing base (72ad81f) to head (cee8654).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #228   +/-   ##
=======================================
  Coverage   99.35%   99.35%           
=======================================
  Files         178      178           
  Lines        8225     8225           
  Branches      185      185           
=======================================
  Hits         8171     8171           
  Misses         39       39           
  Partials       15       15           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dhoko dhoko changed the title Log source headers inside APIException feat(ApiException): log source headers inside APIException Dec 18, 2025
Copy link
Member

@andrii-bodnar andrii-bodnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhoko thank you for the contribution, looks good to me!

@andrii-bodnar andrii-bodnar merged commit c088f5d into crowdin:main Dec 19, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants