Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Socket hang up while calling API from NodeJS #77

Open
chavda-bhavik opened this issue Sep 30, 2022 · 0 comments
Open

Socket hang up while calling API from NodeJS #77

chavda-bhavik opened this issue Sep 30, 2022 · 0 comments

Comments

@chavda-bhavik
Copy link

I'm calling weasyprint-rest container from NodeJS application. But sometimes API call breaks with error Socket Hang up.

Here is Full error message,

Error: socket hang up
     at connResetException (node:internal/errors70414)
     at Socket.socketOnEnd (node_http_client505:23)
     at Socket.emit (nodeevents525:35)
     at Socket.emit (nodedomain489:12)
     at endReadableNT (node:internal/streams/readable135812)
     at processTicksAndRejections (node:internal/process/task_queues8321)
[Sep-29-2022 094346] [error]: Error: Error: socket hang up

Here is the code I'm using to call weasyprint-rest container,

const axios = require('axios')
const FormData = require('form-data')
const data = new FormData();

const html = `<html>....</html>`;
const images = [ "logo.png", "sign.svg"]
data.append("html", html);
images.forEach( image => data.append('asset[]', fs.createReadStream(path.join(baseDir, `/public/templates/images/${image}`))))

const configConvert = {
	url: process.env.WEASYPRINT_URL,
	headers: { ...data.getHeaders(), 'Connection': 'keep-alive' },
	responseType: "arraybuffer",
	method: "POST",
	data: data
};
    
const pdfResult = await axios(configConvert);
const base64data = new Buffer.from(pdfResult?.data, 'binary');

Any thought on how to fix it? Or any example to call it with library other than axios? Thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant