react-native-pdf icon indicating copy to clipboard operation
react-native-pdf copied to clipboard

Improvement request: add http status code and response body to error object in onError callback

Open heavyskyl opened this issue 3 years ago • 2 comments

react-native version 0.63.2 react-native-pdf version 6.2.0

platform: both

Steps to reproduce

  1. display pdf with the following code
<Pdf
  source={{ uri: 'back-end url here' }}
  onError={(e) => {
     console.log(e);
  }}
/>
  1. return ( or simulate with http proxy ) from the back-end error with code status like 500 (internal server error), 403/401 ( that means session is expired ), etc.

Actual result: in case of http request aborted (ios) error message is:

The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 303.)

in case of server return 403 code status with ( for e.g. ) json body ( {"error": "SessionExpired" } ) error message is:

Load pdf failed. path=/Users/username/Library/Developer/path_to_pdf.pdf

Expected result: error object will have http status code and http response body in case of error so the app will be able to correctly handle different kind of responses from the server. E.g. logout the user if session was expired and server respond with 403/401 code status.

heavyskyl avatar Aug 27 '20 09:08 heavyskyl

Same issue when using base 64 encoded uri

Shafran123 avatar Feb 24 '21 06:02 Shafran123

I'm a little surprised to see this still hasn't been addressed after so long. I too would like to be able to react to whether onError has been caused by a 404 vs a 401 or a 500. It seems a little odd that I can't figure this out from the cryptic error messages provided.

apbarratt avatar Feb 01 '24 19:02 apbarratt