RestAssured I miss one field when extracting Response Body from Response

22 views Asked by At

I have got strange problem with RestAssured because I don't see one of the field.

when I use postman to send request

curl --location 'http://localhost:8080/team/testing-endpoint' as response I get:

{ "timestamp": "2024-03-09T18:24:10.622+00:00", "status": 404, "error": "Not Found", "message": "UserName: userNameToDeletedoes not belong to team: teamName", "path": "/team/testing-endpoint" }

when I use RestAssured:

given() .get("team/testing-endpoint") .then().extract().response().asString();

I get :

{"timestamp":"2024-03-09T18:40:10.295+00:00","status":404,"error":"Not Found","path":"/team/testing-endpoint"}

Why I didn't get a field message in response in RestAssured?

For Testing Purpose I just created simple endpoint:

@GetMapping("testing-endpoint")
public ResponseEntity<?> testingEndpoint() {

   String userNameToDelete = "userNameToDelete";
   String teamName = "teamName";

   throw new ResponseStatusException(HttpStatus.NOT_FOUND,
            "UserName: " + userNameToDelete +  "does not belong to teammmmm: " + teamName);
}

Thanks

I looked through google but found no answer. I want to get access to "message" field by using RestAssured response

0

There are 0 answers