Skip to content

413 Request Entity Too Large when encoding/decoding from syllabic languages #54

@ttreder-explorance

Description

@ttreder-explorance

Describe the bug
When using the deep-node library to translate batches of text in syllabic languages (Japanese, Arabic, Chinese, etc.), despite making sure the payload stays under 130000 bytes, we still get 413 errors.

To Reproduce
Steps to reproduce the behavior:

  1. Loop over the texts in the Feedback column of this file
  2. When you reach 130k bytes (calculate using a URLSearchParams, just like the library is doing) send the comments
  3. When sending the 4th batch of 129145 bytes you should get the 413 error (event tho your first batch was 129640 bytes long)

Expected behavior
The coding/decoding of the texts should be consistent, avoiding any 413 errors.

Desktop:

  • OS: macOS 15 // Windows 11
  • Env: NodeJS (Express)
  • Version: 18

Additional context
Code example to reproduce:

let searchParams = new URLSearchParams();
let commentsToTranslate: string[] = [];
let totalBatchNumber = 0
allComments.forEach((comment) => {
  searchParams.append("text", comment);
  const commentsByteLength = searchParams.toString().length;
  console.log(commentsByteLength);
  // If we would go above the byte threshold on the request payload, send the request
  if (commentsByteLength > 130000) { // Leaving more than 1000 bytes should be well enough for the target_lang param
    totalBatchNumber += 1;
    console.log(`sending batch nb${totalBatchNumber}`);
    const translations = await translator.translateText(commentsToTranslate), null, "en");
    // Do something with the translations here
    commentsToTranslate = [];
  else {
    commentsToTranslate.push(comment);
  }
}

Note: Using a decodeURIComponent on the server might be the cause of the issue as it does not behave the same way as URLSearchParams

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