Skip to content

Commit

Permalink
protect against webpack 5 removing Buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaster committed Oct 26, 2021
1 parent bbf465c commit 23df8b4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/sdk-rtl/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,13 @@ function bufferString(val: any) {
} catch (e: any) {
// Supremely ugly hack. If we get here, we must be in Node (or IE 11, but who cares about that?)
// Node requires an import from `util` for TextDecoder to be found BUT it "just has" Buffer unless WebPack messes us up
if (val instanceof Buffer) {
result = Buffer.from(val).toString(utf8)
} else {
try {
if (val instanceof Buffer) {
result = Buffer.from(val).toString(utf8)
} else {
result = JSON.stringify(val)
}
} catch (err: any) {
// The fallback logic here will at least give us some information about the error being thrown
result = JSON.stringify(val)
}
Expand Down

0 comments on commit 23df8b4

Please sign in to comment.