Skip to content

Commit

Permalink
fix(rocketact-web-console): handle upstream error in API proxy
Browse files Browse the repository at this point in the history
fix #22
  • Loading branch information
loveky committed Mar 29, 2019
1 parent 3dec1fa commit eea248f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/rocketact-web-console/src/server/proxyAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ let ruleCache: Array<IProxyRule> = [];
const ruleMatchRegExpCache: { [index: string]: RegExp } = {};
const proxy = httpProxy.createProxyServer({});

proxy.on("error", (err, req, res) => {
res.writeHead(500, {
"Content-Type": "text/plain"
});

res.end(`Rocketact: Failed to get response from upstream.`);
});

const loadFromDisk = () => {
try {
ruleCache = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf-8").toString());
Expand Down

0 comments on commit eea248f

Please sign in to comment.