Sunbird-RC / community

Repo to enable discussions, issue tracking & documentation for the Sunbird-RC projects
MIT License
12 stars 23 forks source link

Receiving HTTP 200 status code for unsuccessful requests #96

Open gamemaker1 opened 3 years ago

gamemaker1 commented 3 years ago

Describe the bug I receive a HTTP 200 status code and responseCode OK in the response payload for an unsuccessful request.

To Reproduce Steps to reproduce the behavior:

  1. Run the registry using docker. Here is a script to help with that.
  2. Make the following request:
~ > echo '{"name": "B Teacher", "phoneNumber": "1122334455", "school": "MP Public School"}' | http post :8081/api/v1/Teacher/invite 'Content-Type: application/json'
  1. See error:
HTTP/1.1 200 
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Connection: keep-alive
Content-Length: 829
Content-Type: application/json
Date: Sat, 09 Oct 2021 11:58:01 GMT
Expires: 0
Keep-Alive: timeout=60
Pragma: no-cache
Vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

{
    "ets": 1633780681268,
    "id": "",
    "params": {
        "err": "",
        "errmsg": "Exception executing consequence for rule \"Create entity owner for newly added owner fields\" in io.opensaber.workflow: [Error: keycloakAdminUtil.createUser(stateDefinition.getEntityName(), stateDefinition.getUpdated().get(\"userId\").textValue(),        stateDefinition.getUpdated().get(\"email\").textValue(), stateDefinition.getUpdated().get(\"mobile\").textValue()): RESTEASY004655: Unable to invoke request: org.apache.http.conn.HttpHostConnectException: Connect to localhost:9990 [localhost/127.0.0.1] failed: Connection refused (Connection refused)]\n[Near : {... String owner = keycloakAdminUt ....}]\n             ^\n[Line: 1, Column: 1]",
        "msgid": "54102bd6-ed23-4784-97f6-de9c90dd3f87",
        "resmsgid": "",
        "status": "UNSUCCESSFUL"
    },
    "responseCode": "OK",
    "ver": "1.0"
}

Expected behavior Since it is an internal server error, it would be more appropriate to return a HTTP 500 status code instead. Also, when there is a validation error, it would be better to return a HTTP 400 status code instead of 200.

Desktop (please complete the following information):

pramodkvarma commented 3 years ago

@dileepbapat can you help or have @tejash-jl step in to help?

tejash-jl commented 3 years ago

@gamemaker1 I'll fix this issue.