I am attempting to use OpenAI image generating API. I have the catch error set to console log the error. I'm currently getting a "SyntaxError: Unexpected token 'I', "Incorrect "... is not valid JSON" as the alert and in the console it says "POST "http://localhost:8080/api/v1/dalle" 500 (Internal Server Error)." I'm not too familiar with backend programming so any help is greatly appreciated.
This is the codesnippet where the error is originating according to the console
const generateImage = async () => {
if (form.prompt) {
try {
setGeneratingImg(true);
const response = await fetch('http://localhost:8080/api/v1/dalle', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
prompt: form.prompt,
}),
});
const data = await response.json();
setForm({ ...form, photo: `data:image/jpeg;base64,${data.photo}` });
} catch (err) {
alert(err);
} finally {
setGeneratingImg(false);
}
} else {
alert('Please provide proper prompt');
}
};
I tried changing POST to GET and I tried adjusting http > https. I tried res.status vs res.send - no difference