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 @@ -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+
95102function 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
You can’t perform that action at this time.
0 commit comments