@@ -138,6 +138,39 @@ async function jsonAsk(url, fetchOptions = {}) {
138
138
if ( json . match ( / S e r v i c e n o d e i s n o t r e a d y : / ) ) {
139
139
return
140
140
}
141
+ // handle 2021 change
142
+ // https://github.com/oxen-io/oxen-storage-server/commit/7f148b4d6ee7f6052fbab4e6234ab3a4411fd95c
143
+ if ( json . match ( / I n v a l i d l a s t _ h a s h : e x p e c t e d b a s e 6 4 \( 4 3 c h a r s \) / ) ) {
144
+ // just clear out last hash
145
+ return {
146
+ lastHash : ' ' ,
147
+ messages : [ ] ,
148
+ }
149
+ /*
150
+ const bodyData = JSON.parse(fetchOptions.body)
151
+ if (bodyData?.params?.lastHash?.length !== 43) {
152
+ // retry without
153
+ console.warn('lib::jsonAsk - last_hash', bodyData.params.lastHash, 'is invalid, retrying without, so we can retrieve anything', fetchOptions)
154
+ //const props = ['method', 'body', 'headers', 'timeout']
155
+ delete bodyData.params.lastHash
156
+ fetchOptions.body = JSON.stringify(bodyData)
157
+ const json2 = await textAsk(url, fetchOptions)
158
+ // huh this doesn't have a lastHash
159
+ console.log('got', json2)
160
+ try {
161
+ const obj = JSON.parse(json2)
162
+
163
+ return obj
164
+ } catch (e) {
165
+ console.error('lib::jsonAsk - err', e, 'json', json2, 'options', fetchOptions)
166
+ return
167
+ }
168
+ return jsonAsk(url, fetchOptions)
169
+ }
170
+ console.warn('got invalid last_hash', bodyData.params.lastHash, 'is 43...', bodyData)
171
+ return
172
+ */
173
+ }
141
174
try {
142
175
const obj = JSON . parse ( json )
143
176
return obj
0 commit comments