Merge pull request #884 from mempool/simon/electrs-error-handling
Handle new type of Electrum Server error.
This commit is contained in:
		
						commit
						b8f3c1f124
					
				@ -87,11 +87,8 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
 | 
				
			|||||||
        },
 | 
					        },
 | 
				
			||||||
        'electrum': true,
 | 
					        'electrum': true,
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e: any) {
 | 
				
			||||||
      if (e === 'failed to get confirmed status') {
 | 
					      throw new Error(typeof e === 'string' ? e : e && e.message || e);
 | 
				
			||||||
        e = 'The number of transactions on this address exceeds the Electrum server limit';
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      throw new Error(typeof e === 'string' ? e : 'Error');
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -124,12 +121,9 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return transactions;
 | 
					      return transactions;
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e: any) {
 | 
				
			||||||
      loadingIndicators.setProgress('address-' + address, 100);
 | 
					      loadingIndicators.setProgress('address-' + address, 100);
 | 
				
			||||||
      if (e === 'failed to get confirmed status') {
 | 
					      throw new Error(typeof e === 'string' ? e : e && e.message || e);
 | 
				
			||||||
        e = 'The number of transactions on this address exceeds the Electrum server limit';
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      throw new Error(typeof e === 'string' ? e : 'Error');
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -613,7 +613,7 @@ class Routes {
 | 
				
			|||||||
      const addressData = await bitcoinApi.$getAddress(req.params.address);
 | 
					      const addressData = await bitcoinApi.$getAddress(req.params.address);
 | 
				
			||||||
      res.json(addressData);
 | 
					      res.json(addressData);
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e) {
 | 
				
			||||||
      if (e instanceof Error && e.message && e.message.indexOf('exceeds') > 0) {
 | 
					      if (e instanceof Error && e.message && (e.message.indexOf('too long') > 0 || e.message.indexOf('confirmed status') > 0)) {
 | 
				
			||||||
        return res.status(413).send(e instanceof Error ? e.message : e);
 | 
					        return res.status(413).send(e instanceof Error ? e.message : e);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      res.status(500).send(e instanceof Error ? e.message : e);
 | 
					      res.status(500).send(e instanceof Error ? e.message : e);
 | 
				
			||||||
@ -630,7 +630,7 @@ class Routes {
 | 
				
			|||||||
      const transactions = await bitcoinApi.$getAddressTransactions(req.params.address, req.params.txId);
 | 
					      const transactions = await bitcoinApi.$getAddressTransactions(req.params.address, req.params.txId);
 | 
				
			||||||
      res.json(transactions);
 | 
					      res.json(transactions);
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e) {
 | 
				
			||||||
      if (e instanceof Error && e.message && e.message.indexOf('exceeds') > 0) {
 | 
					      if (e instanceof Error && e.message && (e.message.indexOf('too long') > 0 || e.message.indexOf('confirmed status') > 0)) {
 | 
				
			||||||
        return res.status(413).send(e instanceof Error ? e.message : e);
 | 
					        return res.status(413).send(e instanceof Error ? e.message : e);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      res.status(500).send(e instanceof Error ? e.message : e);
 | 
					      res.status(500).send(e instanceof Error ? e.message : e);
 | 
				
			||||||
 | 
				
			|||||||
@ -122,10 +122,11 @@
 | 
				
			|||||||
  </ng-template>
 | 
					  </ng-template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <ng-template [ngIf]="error">
 | 
					  <ng-template [ngIf]="error">
 | 
				
			||||||
 | 
					    <br>
 | 
				
			||||||
    <div class="text-center">
 | 
					    <div class="text-center">
 | 
				
			||||||
      <span i18n="address.error.loading-address-data">Error loading address data.</span>
 | 
					      <span i18n="address.error.loading-address-data">Error loading address data.</span>
 | 
				
			||||||
      <br>
 | 
					      <br>
 | 
				
			||||||
      <ng-template #displayServerError><i>{{ error.error }}</i></ng-template>
 | 
					      <ng-template #displayServerError><i class="small">({{ error.error }})</i></ng-template>
 | 
				
			||||||
      <ng-template [ngIf]="error.status === 413 || error.status === 405" [ngIfElse]="displayServerError">
 | 
					      <ng-template [ngIf]="error.status === 413 || error.status === 405" [ngIfElse]="displayServerError">
 | 
				
			||||||
        <ng-container i18n="Electrum server limit exceeded error">
 | 
					        <ng-container i18n="Electrum server limit exceeded error">
 | 
				
			||||||
          <i>The number of transactions on this address exceeds the Electrum server limit</i>
 | 
					          <i>The number of transactions on this address exceeds the Electrum server limit</i>
 | 
				
			||||||
@ -136,6 +137,8 @@
 | 
				
			|||||||
        <a href="https://mempool.space/address/{{ addressString }}" target="_blank">https://mempool.space/address/{{ addressString }}</a>
 | 
					        <a href="https://mempool.space/address/{{ addressString }}" target="_blank">https://mempool.space/address/{{ addressString }}</a>
 | 
				
			||||||
        <br>
 | 
					        <br>
 | 
				
			||||||
        <a href="http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/address/{{ addressString }}" target="_blank">http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/address/{{ addressString }}</a>
 | 
					        <a href="http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/address/{{ addressString }}" target="_blank">http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/address/{{ addressString }}</a>
 | 
				
			||||||
 | 
					        <br><br>
 | 
				
			||||||
 | 
					        <i class="small">({{ error.error }})</i>
 | 
				
			||||||
      </ng-template>
 | 
					      </ng-template>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
  </ng-template>
 | 
					  </ng-template>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user