Firebase storage.uploadBytesResumable returns ‘success’ when it fails – how to catch error then?

It logs this error: Error: PERMISSION_DENIED: Permission denied

But the result in the code below is as shown in the image:

const result = await uploadBytesResumable(ref, file, metadata)

How then can we detect the error? It’s not helpful to merely have it logged and have the app carry on like no error ever occurred.

enter image description here