File tree Expand file tree Collapse file tree
packages/wallet/core/src/state/arweave Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
9198function 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
You can’t perform that action at this time.
0 commit comments