retrieve error on client when using `startUpload` provided by `useUploadThing`

Hello, I am trying to somehow obtain the error reason on the client if uploading the image fails. However, the response I get is undefined. I thought maybe i would need to return something from the onUploadComplete callback, but this doesn't allow any returned value as its return type is void. How should I be returning error messages onto the client?
<input
ref={fileInputRef}
type="file"
className="hidden"
accept="image/png, image/jpeg, image/webp"
onChange={async (e) => {
const file = e.target.files?.[0];
if (!file) return;

const uploadedFiles = await startUpload([file]);
console.log('response', uploadedFiles); // undefined if error uploading, eg filetype invalid or file too large
}}
/>
<input
ref={fileInputRef}
type="file"
className="hidden"
accept="image/png, image/jpeg, image/webp"
onChange={async (e) => {
const file = e.target.files?.[0];
if (!file) return;

const uploadedFiles = await startUpload([file]);
console.log('response', uploadedFiles); // undefined if error uploading, eg filetype invalid or file too large
}}
/>
1 Reply
v28
v28OP3mo ago
bump

Did you find this page helpful?