diff --git a/.gitignore b/.gitignore index cdd74c6..9bbff4e 100644 --- a/.gitignore +++ b/.gitignore @@ -104,3 +104,5 @@ dist .tern-port examples/**/yarn.lock + +.DS_store diff --git a/lib/browser.ts b/lib/browser.ts index 40d9656..7a2fa76 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -31,8 +31,20 @@ function createRpcFetcher(url: string, method: string): NextRpcCall { }, }) .then(function (res) { + const statusError = new Error('Unexpected HTTP status ' + res.status); + if (res.status === 502) { + return res.json().then( + (json) => { + if (json.error && typeof json.error.message === 'string') { + return json; + } + return Promise.reject(statusError); + }, + (err) => Promise.reject(statusError) + ); + } if (!res.ok) { - throw new Error('Unexpected HTTP status ' + res.status); + throw statusError; } return res.json(); }) diff --git a/lib/server.ts b/lib/server.ts index fd040bc..eca175f 100644 --- a/lib/server.ts +++ b/lib/server.ts @@ -68,7 +68,7 @@ export function createRpcHandler( message = `Invalid value thrown in "${method}", must be instance of Error`, stack = undefined, } = error instanceof Error ? error : {}; - return res.json({ + return res.status(502).json({ error: { name, message, diff --git a/yarn.lock b/yarn.lock index 46bbbee..057fcc5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -883,9 +883,9 @@ "@types/react" "*" "@types/react@*", "@types/react@^17.0.35": - version "17.0.35" - resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.35.tgz#217164cf830267d56cd1aec09dcf25a541eedd4c" - integrity sha512-r3C8/TJuri/SLZiiwwxQoLAoavaczARfT9up9b4Jr65+ErAUX3MIkU0oMOQnrpfgHme8zIqZLX7O5nnjm5Wayw== + version "17.0.36" + resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.36.tgz#0d81e0e2419e6a8e9ba6af5e3a0608e70835d7d1" + integrity sha512-CUFUp01OdfbpN/76v4koqgcpcRGT3sYOq3U3N6q0ZVGcyeP40NUdVU+EWe3hs34RNaTefiYyBzOpxBBidCc5zw== dependencies: "@types/prop-types" "*" "@types/scheduler" "*"