@@ -34,12 +34,13 @@ export function decodePayload(
34
34
// eslint-disable-next-line @typescript-eslint/no-explicit-any
35
35
) : Payload | Record < any , any > | string {
36
36
const encoding = atob ( String ( payload ?. metadata ?. encoding ?? '' ) ) ;
37
+
37
38
// Help users out with an english encoding
38
39
( payload . metadata . encodingDecoded as unknown as string ) = encoding ;
39
40
40
- if ( encoding . startsWith ( 'json/' ) ) {
41
+ if ( encoding ? .startsWith ( 'json/' ) ) {
41
42
try {
42
- return parseWithBigInt ( atob ( String ( payload . data ) ) ) ;
43
+ return parseWithBigInt ( atob ( String ( payload ? .data ?? '' ) ) ) ;
43
44
} catch ( _e ) {
44
45
// Couldn't correctly decode this just let the user deal with the data as is
45
46
}
@@ -119,7 +120,7 @@ export const decodeAllPotentialPayloadsWithCodec = async (
119
120
JSONPayload = payloads . map ( decodePayload ) ;
120
121
}
121
122
anyAttributes [ key ] = JSONPayload ;
122
- } else if ( key === 'encodedAttributes' ) {
123
+ } else if ( key === 'encodedAttributes' && anyAttributes [ key ] ) {
123
124
// Can expand if more fields have single payload
124
125
// eslint-disable-next-line @typescript-eslint/no-explicit-any
125
126
let JSONPayload : string | Payload | Record < any , any > ;
@@ -175,7 +176,7 @@ export const decodeAllPotentialPayloadsWithWebsockets = async (
175
176
JSONPayload = payloads . map ( decodePayload ) ;
176
177
}
177
178
anyAttributes [ key ] = JSONPayload ;
178
- } else if ( key === 'encodedAttributes' ) {
179
+ } else if ( key === 'encodedAttributes' && anyAttributes [ key ] ) {
179
180
// Can expand if more fields have single payload
180
181
// eslint-disable-next-line @typescript-eslint/no-explicit-any
181
182
let JSONPayload : string | Payload | Record < any , any > ;
0 commit comments