How to get error message from array buffer
I finally found the solution I needed here:
let message = String.fromCharCode.apply(
null,
new Uint8Array(errorResponse.body));
However, because I'm using TypeScript I was getting some kind of annoying message about errorResponse.body
not being assignable to type number[]
, so I'm doing it like this:
let message = String.fromCharCode.apply(
null,
new Uint8Array(errorResponse.body) as any);
Also note that because my response body had an odd number of characters, I had to use Uint8Array
instead of Uint16Array
. See this helpful answer for details.