REST Assured Log Response if Error or Status Code Matches Some Value

Profile picture for user devraj

If you're only interested in printing the response body if an error occur then you can use:

.log().ifError()

make sure you are using .log().ifError() just after than otherwise logs will not show. It logs everything only if an error occurs (status code >= 400).

REST Assured Log only the status

.log().status();		

REST Assured Log if status code is equal to

.log().ifStatusCodeIsEqualTo(202)

log if the status code matches the supplied Hamcrest matcher

.log().ifStatusCodeMatches(equalTo(200));