I'm using an API library in Node that doesn't return the status code of the HTTP response. However, it does return the response headers, which look like this:
{ ...
status: '200 OK',
... }
Is there any Node library I can use to parse the status code from the returned object's status? Will a crude +res.status.slice(0, 3)
do?
EDIT: Link to the library.
All HTTP status codes have 3 digits, so your slice example will work. However, I would personally just split on space:
var code = status.split(' ')[0];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.