You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError when Downloading to PDF in Azure App Service: undici failure #1990
I'm running an express app using Node v18.19.1. My endpoint does the following:
Saves a document to a sharepoint folder
Performs the download/convert to pdf
Saves the downloaded pdf to a Mongo db.
Deletes the original file
Steps 1, 2, and 4 use the @microsoft/microsoft-graph-client@3.0.7 package. This all works locally. However, when I deploy it to my Azure App Services (running Windows and Node v18.19.1), it breaks at step 2 with the following error:
TypeError: fetch failed at node:internal/deps/undici/undici:12625:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
The conversion download method:
constconversionDownloadToPdf=async(fileItemId)=>{try{console.log(chalk.blue(`Attempting to downloaded file (${fileItemId})...`));constresponse=awaitclient.api(`drives/${process.env.DRIVE_ID}/items/${fileItemId}/content?format=pdf`).responseType(ResponseType.RAW)// ensure raw stream.get();conststream=awaitapiRequest.responseType(ResponseType.RAW).get();// BREAKS HEREconsole.log(chalk.blue(`Stream downloaded. Streaming to buffer...`));returnawaittoBuffer(stream);}catch(error){console.error(chalk.red(`Full error details:`));console.error(chalk.red(`Message: ${error.message}`));console.error(chalk.red(`Status Code: ${error.statusCode}`));console.error(chalk.red(`Code: ${error.code}`));console.error(chalk.red(`Stack: ${error.stack}`));// Log the cause if available (undici errors have this)if(error.cause)console.error(chalk.red(`Cause: ${JSON.stringify(error.cause,null,2)}`));throwerror;}}
Do I need to use that ProxyAgent? Do you have official docs on a workaround?
changed the title [-]TypeError: fetch failed at node:internal/deps/undici/undici:12625:11[/-][+]TypeError when Downloading to PDF in Azure App Service: undici failure[/+]on Nov 18, 2025
constconversionDownloadToPdf_usingFetch=async(fileItemId)=>{try{// Get access tokenconstauthProvider=newDocMgmtAuthentication();constaccessToken=awaitauthProvider.getAccessToken();// Use native fetch() to call Microsoft Graph directlyconstresponse=awaitfetch(`https://graph.microsoft.com/v1.0/drives/${process.env.DRIVE_ID}/items/${fileItemId}/content?format=pdf`,{headers: {'Authorization': `Bearer ${accessToken}`}});if(!response.ok){thrownewError(`Graph API error: ${response.status}${response.statusText}`);}constarrayBuffer=awaitresponse.arrayBuffer();constbuffer=Buffer.from(arrayBuffer);returnbuffer;}catch(error){throwerror;}}
I got this error:
TypeError: fetch failed
at node:internal/deps/undici/undici:12625:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async conversionDownloadToPdf (C:\home\site\wwwroot\util\msGraph.js:34:22)
at async C:\home\site\wwwroot\controllers\my.controller.js:92:27
at async Promise.all (index 0)
at async Object.uploadDocs (C:\home\site\wwwroot\controllers\doc.controller.js:65:3)
at async C:\home\site\wwwroot\routes.js:71:18 {cause: Error: getaddrinfo ENOTFOUND usgovtexas1-mediap.svc.ms
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)
at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:128:17)
{
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'usgovtexas1-mediap.svc.ms'
}
After clicking the upload button on my frontend code (which triggers this function) several times, the conversion ends up working after the 3-4 attempt. Still not sure what the cause of the initial 1-3 failures is.
I added retry logic to this method so that the initial click runs the function up to 3 times if it fails.
Erik Rasmussen (@UnstoppableMango) Thank you for the reference. I guess I'll pass on that one until they can release something official. I guess I just need to reach MS Graph team directly about this issue.
Activity
[-]TypeError: fetch failed at node:internal/deps/undici/undici:12625:11[/-][+]TypeError when Downloading to PDF in Azure App Service: undici failure[/+]am35-00 commentedon Nov 19, 2025
I also tried using a raw fetch like this:
I got this error:
am35-00 commentedon Nov 21, 2025
After clicking the upload button on my frontend code (which triggers this function) several times, the conversion ends up working after the 3-4 attempt. Still not sure what the cause of the initial 1-3 failures is.
I added retry logic to this method so that the initial click runs the function up to 3 times if it fails.
lorand93 commentedon Nov 27, 2025
I recommend moving away from this library as it's not maintained anymore.
Not throwing snowballs at it, jus stating the obvious facts.
am35-00 commentedon Dec 1, 2025
Lorand Sandor (@lorand93) Oh wow. I just looked at the commit history. You think MS Graph is going away? Is there a better library to use?
UnstoppableMango commentedon Dec 18, 2025
There is a preview SDK under relatively active development over at https://github.com/microsoftgraph/msgraph-sdk-typescript
However, be aware it is pre-release software
am35-00 commentedon Dec 18, 2025
Erik Rasmussen (@UnstoppableMango) Thank you for the reference. I guess I'll pass on that one until they can release something official. I guess I just need to reach MS Graph team directly about this issue.