Skip to content

Commit 83d022d

Browse files
committed
Initial attempt to grab error.message from response body
1 parent 55f3f83 commit 83d022d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/storage/src/platform/browser/connection.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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. */

packages/storage/src/platform/node/connection.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)