Skip to content

Commit e9d5f6e

Browse files
committed
DO NOT MERGE: HACK
1 parent fca8235 commit e9d5f6e

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

  • packages/wallet/core/src/state/arweave

packages/wallet/core/src/state/arweave/index.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ function sameAddress(left: Address.Address | undefined, right: Address.Address |
8888
: left !== undefined && right !== undefined && Address.isEqual(left, right)
8989
}
9090

91+
function allowsPlainTextJsonFallback(entry: ItemEntry): boolean {
92+
return (
93+
entry.tags.Type === 'payload' &&
94+
(entry.tags['Payload-Type'] === 'message' || entry.tags['Payload-Type'] === 'digest')
95+
)
96+
}
97+
9198
function mergeConfigurations(base: Config.Config | undefined, next: Config.Config): Config.Config {
9299
if (!base) {
93100
return next
@@ -413,8 +420,19 @@ export class Reader implements ReaderInterface {
413420
throw new Error(`failed to fetch arweave item ${entry.id}: ${response.status}`)
414421
}
415422

416-
const data =
417-
entry.tags['Content-Type'] === 'application/json' ? await response.json() : (await response.text()).trim()
423+
const text = (await response.text()).trim()
424+
let data: unknown = text
425+
426+
if (entry.tags['Content-Type'] === 'application/json') {
427+
try {
428+
data = JSON.parse(text)
429+
} catch (error) {
430+
if (!allowsPlainTextJsonFallback(entry)) {
431+
throw error
432+
}
433+
}
434+
}
435+
418436
return { ...entry.tags, data } as T
419437
}
420438

0 commit comments

Comments
 (0)