Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3637

understanding the error response to an http request to rest api

$
0
0

This is a simple request to a REST API using AXIOS:

  await axios.request({    url: 'https://gorest.co.in/public/v2/users',    method: 'POST',    data: {"id":2925,"name":"Himani Rana","email":"rana_himani@boehm-okeefe.biz","gender":"female","status":"inactive"})   .catch(error => {      console.log(error);    });  }

This EMAIL is ALREADY taken. So this raises an exception because all users must have unique emails.

This code logs the following error:

{"message": "Network Error","name": "Error","fileName": "https://c.staticblitz.com/d/webcontainer.a330fe2aef0d6950e5edf5ad2e9521381ac64c16.js line 15 > eval","lineNumber": 3,"columnNumber": 8750,"stack": "e.exports@https://typescript-9ggya9.stackblitz.io/turbo_modules/axios@0.25.0/dist/axios.min.js:3:8750\ne.exports/</g.onerror@https://typescript-9ggya9.stackblitz.io/turbo_modules/axios@0.25.0/dist/axios.min.js:3:7558\n","config": {"transitional": {"silentJSONParsing": true,"forcedJSONParsing": true,"clarifyTimeoutError": false},"transformRequest": [null],"transformResponse": [null],"timeout": 0,"xsrfCookieName": "XSRF-TOKEN","xsrfHeaderName": "X-XSRF-TOKEN","maxContentLength": -1,"maxBodyLength": -1,"headers": {"Accept": "application/json, text/plain, */*","Content-Type": "application/json","Authorization": "Token 1a459dd3d2e13a989f01565f5f1ba32350f8216897bb7fee5493feb210a06"},"url": "https://gorest.co.in/public/v2/users","method": "post","data": "{\"id\":2925,\"name\":\"Himani Rana\",\"email\":\"rana_himani@boehm-okeefe.biz\",\"gender\":\"female\",\"status\":\"inactive\"}"},"status": null}

This is difficult to read and when I went through it carefully, I did not see something that helps me identify the error apart from a message that says "Network Error".

NOW, doing this http request with POSTMAN or THUNDER CLIENT simply shows:

[  {"field": "email","message": "has already been taken"  }]

How do these REST clients identify the error properly but AXIOS doesn't?


Viewing all articles
Browse latest Browse all 3637

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>