'how to send the stack error in a file in a form data discord webhook

i have a function with winston_transport and axios and i want to send discord web hook message with axios in content type multipart/form-data

on the webhook discord documentation it says to put payload_json which I did but I got a 400 error return and I don't see why

i have a function with winston_transport and axios and i want to send discord web hook message with axios in content type multipart/form-data

on the webhook discord documentation it says to put payload_json which I did but I got a 400 error return and I don't see why

here is my form data that I send with error request 400

FormData {
  _overheadLength: 111,
  _valueLength: 818,
  _valuesToMeasure: [],
  writable: false,
  readable: true,
  dataSize: 0,
  maxDataSize: 2097152,
  pauseStreams: true,
  _released: false,
  _streams: [
    '----------------------------579151143396808387072667\r\n' +
      'Content-Disposition: form-data; name="payload_json"\r\n' +
      '\r\n',
    '{"content":"Red Alert !!! - 17 April 2022 10:22:15","username":"Skynet","attachments":[],"embeds":[{"title":":face_with_symbols_over_mouth: - Hello !","description":"\\"Error: toto\\\\n    at discord (file:///home/lidian/directory_Project/react-simple/api/src/controllers/DiscordLogger.js:37:85)\\\\n    at Layer.handle [as handle_request] (/home/lidian/directory_Project/react-simple/api/node_modules/express/lib/router/layer.js:95:5)\\\\n    at next (/home/lidian/directory_Project/react-simple/api/node_modules/express/lib/router/route.js:137:13)\\\\n    at Route.dispatch (/home/lidian/directory_Project/react-simple/api/node_modules/express/lib/router/route.js:112:3)\\\\n    at....","color":"10038562","image":{"url":""},"fields":[{"name":"Good Luck","value":":four_leaf_clover:"}],"timestamp":"2022-04-17T08:22:15.059Z"}]}',
    [Function: bound ]
  ],
  _currentStream: null,
  _insideLoop: false,
  _pendingNext: false,
  _boundary: '--------------------------579151143396808387072667'
}
Request failed with status code 400

    class DiscordWinstonTransport extends Transport {
        constructor(opts) {
            super(opts);
            this.level = opts.level || "info";
        }
    
        log(info, callback) {
            setImmediate(() => {
                let { level, title, message, error } = info;
    
                let line = "";
                if (error.stack.length) {
                    let err = JSON.stringify(error.stack);
                    if (err.length > 500) line = err.substring(0, 500) + "....";
                } else {
                    line = "";
                }
            
    
                const msg = {
                    // avatar_url: "https://i.imgur.com/4M34hi2.png",
                    content: `${levels.content} !!! - ${dateFormat}`,
                    username: "Skynet",
                    attachments: [],
                    embeds: [
                        {
                            title: `${levels.emoji} - ${title}`,
                            description: line.length > 0 ? line : message,
                            color: levels.color,
                            image: { url: "" },
                            fields: [
                                // {
                                //  name: "Error",
                                //  value: "error",
                                // },
    
                                {
                                    name: "Good Luck",
                                    value: ":four_leaf_clover:",
                                },
                            ],
                            timestamp: date,
                            
                        },
                    ],
                };
    
                const formdata = new FormData();
                formdata.append("file", error.stack, "file.txt");
                formdata.append("payload_json", JSON.stringify(msg));
                
    
                console.log(formdata);
    
                axios({
                    headers: { "content-type": "multipart/form-data" },
                    // headers: { "content-type": "application/json" },
                    url: envUrl,
                    method: "POST",
                    data: formdata,
                })
                    .then((result) => {
                        callback(null, true);
                    })
                    .catch((error) => {
                        console.log(error.message);
                    });
            });
    
    
            callback(null, true);
        }
    }
    export { DiscordWinstonTransport };



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source