Skip to content

Commit

Permalink
Degrade rpc from v2 to v1 when payload is too big
Browse files Browse the repository at this point in the history
  • Loading branch information
mayfield committed Apr 14, 2024
1 parent 426b2dc commit cc84174
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pages/src/common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,18 @@ if (window.isElectron) {
};
rpcCall = async function(name, ...args) {
const encodedArgs = args.map(x => x !== undefined ? b64urlEncode(JSON.stringify(x)) : '');
const f = await fetch(`/api/rpc/v2/${name}${args.length ? '/' : ''}${encodedArgs.join('/')}`);
const env = await f.json();
let resp = await fetch(`/api/rpc/v2/${name}${args.length ? '/' : ''}${encodedArgs.join('/')}`);
if (!resp.ok && resp.status === 431) {
resp = await fetch(`/api/rpc/v1/${name}`, {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify(args),
});
}
if (!resp.ok) {
throw new Error(`RPC network error: ${resp.status}`);
}
const env = await resp.json();
if (env.warning) {
console.warn(env.warning);
}
Expand Down

0 comments on commit cc84174

Please sign in to comment.