mirror of
https://github.com/mempool/mempool.git
synced 2025-02-23 22:46:54 +01:00
Send 404 when accessing non existing mining pool
This commit is contained in:
parent
796db0de4b
commit
ccafe4a066
2 changed files with 21 additions and 4 deletions
|
@ -80,7 +80,7 @@ class PoolsRepository {
|
|||
/**
|
||||
* Get mining pool statistics for one pool
|
||||
*/
|
||||
public async $getPool(slug: string): Promise<PoolTag> {
|
||||
public async $getPool(slug: string): Promise<PoolTag | null> {
|
||||
const query = `
|
||||
SELECT *
|
||||
FROM pools
|
||||
|
@ -93,6 +93,11 @@ class PoolsRepository {
|
|||
const [rows] = await connection.query(query, [slug]);
|
||||
connection.release();
|
||||
|
||||
if (rows.length < 1) {
|
||||
logger.debug(`$getPool(): slug ${slug} does not match any known pool`);
|
||||
return null;
|
||||
}
|
||||
|
||||
rows[0].regexes = JSON.parse(rows[0].regexes);
|
||||
rows[0].addresses = JSON.parse(rows[0].addresses);
|
||||
|
||||
|
|
|
@ -545,7 +545,11 @@ class Routes {
|
|||
res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString());
|
||||
res.json(stats);
|
||||
} catch (e) {
|
||||
res.status(500).send(e instanceof Error ? e.message : e);
|
||||
if (e instanceof Error && e.message.indexOf('This mining pool does not exist') > -1) {
|
||||
res.status(404).send(e.message);
|
||||
} else {
|
||||
res.status(500).send(e instanceof Error ? e.message : e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -560,7 +564,11 @@ class Routes {
|
|||
res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString());
|
||||
res.json(poolBlocks);
|
||||
} catch (e) {
|
||||
res.status(500).send(e instanceof Error ? e.message : e);
|
||||
if (e instanceof Error && e.message.indexOf('This mining pool does not exist') > -1) {
|
||||
res.status(404).send(e.message);
|
||||
} else {
|
||||
res.status(500).send(e instanceof Error ? e.message : e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -616,7 +624,11 @@ class Routes {
|
|||
hashrates: hashrates,
|
||||
});
|
||||
} catch (e) {
|
||||
res.status(500).send(e instanceof Error ? e.message : e);
|
||||
if (e instanceof Error && e.message.indexOf('This mining pool does not exist') > -1) {
|
||||
res.status(404).send(e.message);
|
||||
} else {
|
||||
res.status(500).send(e instanceof Error ? e.message : e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue