Repository: ecadlabs/taquito
Pull request #1842 (2022-08-22 22:47:45)

1091 http request failed with request info
Thank you for your contribution to Taquito.

Before submitting this PR, please make sure:

- [ ] Your code builds cleanly without any errors or warnings
- [ ] You have added unit tests
- [ ] You have added integration tests (if relevant/appropriate)
- [ ] All public methods or types have TypeDoc coverage with a complete description, and ideally an @example
- [ ] You have added or updated corresponding documentation
- [ ] If relevant, you have written a first draft summary describing the change for inclusion in Release Notes. 

## Release Note Draft Snippet

__If relevant, please write a summary of your change that will be suitable for
inclusion in the Release Notes for the next Taquito release.__


github-actions[bot]: New packages have been deployed to the preview repository at https://npm.preview.tezostaquito.io/.

### Published packages:
```
npm i @taquito/local-forging@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/rpc@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/signer@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/taquito@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/remote-signer@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tezbridge-wallet@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/michelson-encoder@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/contracts-library@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/ledger-signer@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/beacon-wallet@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/http-utils@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tezbridge-signer@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/michel-codec@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/utils@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tzip12@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tzip16@13.0.1-a3a69a3f--1842 --registry https://npm.preview.tezostaquito.io/
```
<!-- Sticky Pull Request Commentdeploy-packages -->
github-actions[bot]: A new deploy preview is available on Netlify at https://a3a69a3f--tezostaquito.netlify.app
<!-- Sticky Pull Request Commentnetlify-preview -->

Patch:
diff --git a/packages/taquito-http-utils/src/taquito-http-utils.ts b/packages/taquito-http-utils/src/taquito-http-utils.ts
index 9774c4ba5..9b2dc1299 100644
--- a/packages/taquito-http-utils/src/taquito-http-utils.ts
+++ b/packages/taquito-http-utils/src/taquito-http-utils.ts
@@ -52,9 +52,7 @@ export class HttpRequestFailed extends Error {
   public name = 'HttpRequestFailed';
 
   constructor(
-    public message: string,
-    public url: string,
-    public method: HttpRequestOptions['method']
+    public message: string
   ) {
     super(message);
   }
@@ -150,7 +148,7 @@ export class HttpBackend {
           url + this.serialize(query)
         );
       } else {
-        throw new HttpRequestFailed(String(err), url + this.serialize(query), method ?? 'GET');
+        throw new HttpRequestFailed(`${method} ${url + this.serialize(query)} ${String(err)}`);
       }
     }
   }


Test patch:
diff --git a/integration-tests/http-backend-request-error-handling.spec.ts b/integration-tests/http-backend-request-error-handling.spec.ts
index fa04953d1..6b5f2eaa5 100644
--- a/integration-tests/http-backend-request-error-handling.spec.ts
+++ b/integration-tests/http-backend-request-error-handling.spec.ts
@@ -1,7 +1,7 @@
 import { HttpBackend } from '@taquito/http-utils';
 
 describe('HttpBackend request', () => {
-    it('will fail with http request url and request method', async (done) => {
+    it('will fail with method and url in error message', async (done) => {
         try {
             const http: HttpBackend = new HttpBackend(1);
             await http.createRequest<string>({
@@ -9,13 +9,14 @@ describe('HttpBackend request', () => {
               url: 'https://mainnet.api.tez.ie/chains/main/blocks/head/hash'
             });
         } catch (err: any) {
-            expect(err.message).toEqual('Error: timeout of 1ms exceeded')
-            expect(err.url).toEqual('https://mainnet.api.tez.ie/chains/main/blocks/head/hash')
-            expect(err.method).toEqual('GET')
+            expect(err.name).toEqual('HttpRequestFailed')
+            expect(err.message).toContain('GET')
+            expect(err.message).toContain('https://mainnet.api.tez.ie/chains/main/blocks/head/hash')
+            expect(err.message).toContain('Error: timeout of 1ms exceeded')
         }
         done()
       });
-      it('will fail with http request url + query and request method', async (done) => {
+      it('will fail with method, url and query in error message', async (done) => {
         try {
             const http: HttpBackend = new HttpBackend(1);
             await http.createRequest<string>({
@@ -26,9 +27,10 @@ describe('HttpBackend request', () => {
               }
             });
         } catch (err: any) {
-            expect(err.message).toEqual('Error: timeout of 1ms exceeded')
-            expect(err.url).toEqual('https://mainnet.api.tez.ie/chains/main/blocks/head/helpers/baking_rights?level=0')
-            expect(err.method).toEqual('GET')
+            expect(err.name).toEqual('HttpRequestFailed')
+            expect(err.message).toContain('GET')
+            expect(err.message).toContain('https://mainnet.api.tez.ie/chains/main/blocks/head/helpers/baking_rights')
+            expect(err.message).toContain('Error: timeout of 1ms exceeded')
         }
         done()
       });