My async function inside my CF worker is not working

When I try to call a async function inside a CF worker it is giving empty response and i am getting the below error

In EIAM Token generation Handler
Auth Token:
end Point:
Status: 403
Response {

}
ERROR: SyntaxError: Unexpected token ‘e’, “error code: 1002” is not valid JSON

My code snippet as below

// This is in index.js imported teh file inside index.js
if (tokens.output === “”) {
await generateAnonymousAccessToken(env)
console.log(": "+ tokens.output)
}

//this is sepererate JS file under src folder in the worker
import { Buffer } from ‘node:buffer’;
import { InputDetails,tokens } from ‘./config’;
export async function generateAnonymousAccessToken(env) {
try {
console.log(“In EIAM Token generation Handler”)
let authToken = ${InputDetails[env]["InputClientId"]}:${InputDetails[env]["InputClientSecret"]};
let buf = Buffer.from(authToken)
authToken = buf.toString(‘base64’);
let url = InputDetails[env][“InputEndpoint”]
const response = await fetch(url, {
method: “POST”,
headers: {
‘Authorization’: 'Basic ’ + authToken,
‘Content-Type’: ‘application/json;charset=UTF-8’
}
});
console.log(“Status: " + response.status)
console.log(response)
let data = await response.json()
tokens.eToken = data[“access_token”]
//return()
} catch (error) {
console.log(“ERROR: " + error)
//return (””)
}
}

so that will be this line:

I’d recommend printing the text response so you can see what the error actually is and go from there
response.text()

Hi @WalshyMVP , thanks for your quick response i am getting empty response if I run the same code in local i am getting the expected output, I have changes as per your response i have below O/p

Status: 403
Response {

}
Data: error code: 1002

Yeah empty response is expected, so you’re getting error 1002 - see: Troubleshooting Cloudflare 1XXX errors · Cloudflare Support docs