Merge pull request #1487 from mempool/nymkappa/bugfix/invalid-pool-handling
Send 404 when accessing non existing mining pool
This commit is contained in:
		
						commit
						ba92284e44
					
				@ -81,7 +81,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
 | 
			
		||||
@ -94,6 +94,11 @@ class PoolsRepository {
 | 
			
		||||
      const [rows] = await connection.query(query, [slug]);
 | 
			
		||||
      connection.release();
 | 
			
		||||
 | 
			
		||||
      if (rows.length < 1) {
 | 
			
		||||
        logger.debug(`$getPool(): slug does not match any known pool`);
 | 
			
		||||
        return null;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      rows[0].regexes = JSON.parse(rows[0].regexes);
 | 
			
		||||
      if (['testnet', 'signet'].includes(config.MEMPOOL.NETWORK)) {
 | 
			
		||||
        rows[0].addresses = []; // pools.json only contains mainnet addresses
 | 
			
		||||
 | 
			
		||||
@ -545,9 +545,13 @@ class Routes {
 | 
			
		||||
      res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString());
 | 
			
		||||
      res.json(stats);
 | 
			
		||||
    } catch (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);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public async $getPoolBlocks(req: Request, res: Response) {
 | 
			
		||||
    try {
 | 
			
		||||
@ -560,9 +564,13 @@ class Routes {
 | 
			
		||||
      res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString());
 | 
			
		||||
      res.json(poolBlocks);
 | 
			
		||||
    } catch (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);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public async $getPools(interval: string, req: Request, res: Response) {
 | 
			
		||||
    try {
 | 
			
		||||
@ -604,9 +612,13 @@ class Routes {
 | 
			
		||||
        hashrates: hashrates,
 | 
			
		||||
      });
 | 
			
		||||
    } catch (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);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public async $getHistoricalHashrate(req: Request, res: Response) {
 | 
			
		||||
    try {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user