Async Await Crashes UDT

So when I run this script in my UDT Debugger it closes right after the first await. Is there something I am doing wrong? No error message in the debugger or InDesign.

(async () => {
    const response = await fetch(url, {
        method: "POST",
        body: JSON.stringify(data),
        headers
    })
    const json = await response.json()

    console.log(json)
})()

This is the documentation I am following to use the deepl api,
Translate text - DeepL API Documentation
I believe I am using it correctly. What say ye?

What’s your url variable? Doesn’t look like you define it.

Oh yes I did define it, sorry I just didn’t include that info because of the api key but I could always swap with a fake one, here is the entire.

var url = “https://api-free.deepl.com/v2/translate”;
var data = { “text”: [“Hello, world!”], “target_lang”: “DE” };
var headers = {
“Authorization”: “DeepL-Auth-Key [123456789]”,
“User-Agent”: “YourApp/1.2.3”,
“Content-Type”: “application/json”
};

(async () => {
const response = await fetch(url, {
method: “POST”,
body: JSON.stringify(data),
headers
})
const json = await response.json()

console.log(json)

})()

Ok cool, just checking the simplest thing first. Gimmie a little while to make a cuppa and get my PC up and running and I’ll have a look in more detail.

Have you added the Deepl domain to requiredPermissions in manifest.json?

To get proper error reporting you need to wrap your code in a try/catch statement, loads of stuff will fail silently in UXP without it.

Okay let me try that, 1 second

Ok so here is what I am trying

(async () => {

    try {
        const response = await fetch(url, {
            method: "POST",
            body: JSON.stringify(data),
            headers
        })
        if (response.ok) {
            const json = await response.json();
            console.log(json);
        } else {
            // Handle non-2xx response
            console.error(`HTTP error! Status: ${response.status}`);
        }
      
    } catch (error) {
        console.log(error)
    }
})()

I’m still getting the same issue where it just crashes, without any error message, I had breakpoints everywhere too. So I decided to go ahead and try it in Postman just to see and I notice I’m getting a 403, response. IDK why though, I contacted the DeepL company for further guidance on this.

When I run it in Playground UDT does not crash and I get the expected errors for making a bad request (I’m not testing with a valid url)

Oh there is a udt playground? Please send me the link

It’s just below the menu bar in UDT…

I’d need to check the docs to confirm but I have a feeling scripts don’t allow for network connections.

Ok yeah sorry For deleting my previous post I thought I misspoke but yes I was correct it is now working but still not working for just the script version(it crashes UDT) but that’s okay I would just use the plugin method instead. Thanks for you help!