File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
packages/storage/src/platform Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -119,7 +119,18 @@ abstract class XhrConnection<T extends ConnectionType>
119119 if ( ! this . sent_ ) {
120120 throw internalError ( 'cannot .getErrorText() before sending' ) ;
121121 }
122- return this . xhr_ . statusText ;
122+ let errorText = '' ;
123+ if ( this . xhr_ . statusText ) {
124+ errorText = this . xhr_ . statusText ;
125+ } else if ( this . xhr_ . response ) {
126+ try {
127+ const parsed = JSON . parse ( this . xhr_ . response ) ;
128+ errorText = parsed . error ?. message || '' ;
129+ } catch ( ignored ) {
130+ /** Don't block if response couldn't be JSON parsed. */
131+ }
132+ }
133+ return errorText ;
123134 }
124135
125136 /** Aborts the request. */
Original file line number Diff line number Diff line change @@ -70,6 +70,12 @@ abstract class FetchConnection<T extends ConnectionType>
7070 this . statusCode_ = response . status ;
7171 this . errorCode_ = ErrorCode . NO_ERROR ;
7272 this . body_ = await response . arrayBuffer ( ) ;
73+ try {
74+ const parsed = await response . json ( ) ;
75+ this . errorText_ = parsed . error ?. message || '' ;
76+ } catch ( ignored ) {
77+ /** Don't block if response couldn't be JSON parsed. */
78+ }
7379 } catch ( e ) {
7480 this . errorText_ = ( e as Error ) ?. message ;
7581 // emulate XHR which sets status to 0 when encountering a network error
You can’t perform that action at this time.
0 commit comments