Skip to content

Commit 362d133

Browse files
committed
DO NOT MERGE: HACK
1 parent 9267ea3 commit 362d133

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
@@ -92,6 +92,13 @@ function sameAddress(left: Address.Address | undefined, right: Address.Address |
9292
: left !== undefined && right !== undefined && Address.isEqual(left, right)
9393
}
9494

95+
function allowsPlainTextJsonFallback(entry: ItemEntry): boolean {
96+
return (
97+
entry.tags.Type === 'payload' &&
98+
(entry.tags['Payload-Type'] === 'message' || entry.tags['Payload-Type'] === 'digest')
99+
)
100+
}
101+
95102
function mergeConfigurations(base: Config.Config | undefined, next: Config.Config): Config.Config {
96103
if (!base) {
97104
return next
@@ -417,8 +424,19 @@ export class Reader implements ReaderInterface {
417424
throw new Error(`failed to fetch arweave item ${entry.id}: ${response.status}`)
418425
}
419426

420-
const data =
421-
entry.tags['Content-Type'] === 'application/json' ? await response.json() : (await response.text()).trim()
427+
const text = (await response.text()).trim()
428+
let data: unknown = text
429+
430+
if (entry.tags['Content-Type'] === 'application/json') {
431+
try {
432+
data = JSON.parse(text)
433+
} catch (error) {
434+
if (!allowsPlainTextJsonFallback(entry)) {
435+
throw error
436+
}
437+
}
438+
}
439+
422440
return { ...entry.tags, data } as T
423441
}
424442

0 commit comments

Comments
 (0)