Hello.
I want to show detail error message with body response when request has filed.
it('show detail error when status expect fail', () => {
request(server)
.get(ruiPath)
.expect(200)
.then(() => { // some expect } )
.then(done)
.catch((err) => {
// I wanna get response here to display error message more kindly with response body sent from server.
console.error(err.response.body);
done.fail(err);
});
}
use .end((err, res) => { after the .expect(200)
The same question.
I know the .end(fn) can got the response.
But have to change too much code for that.Because it can't .then after .end.
MayBe supertest can inject the response to the error object.
I think this should be re-opened. Using the promises interface, or async/await, I'd expect to be able to do this:
return request
.get(url)
.expect(200)
.catch(e => {
console.log(e, e.response, e.status);
});
...just as in superagent, for example: https://github.com/visionmedia/superagent/issues/1074. I don't want to use .end callbacks. Is this something that could be achieved?
Looks like you need to proxy Test.prototype.then in the same way as Test.prototype.end (see https://github.com/visionmedia/superagent/blob/1724997edc451df62139385266d17438002d918f/lib/request-base.js#L231).