Problem with request body params - how to handle error code 500?

497 views Asked by At

This is my params model:

data class ProductParams(
    val name: String,
    val key: String,
    val parentProduct: Int?,
)

I send params:

{
    "name": null,
    "parentProduct": null,
    "key": "TEST"
}

I get error code 500. How can I handle it?

1

There are 1 answers

0
Mitch On

Edit

Try setting name param to a String not null as its not an optional val.

Take a look at Http Status Codes in your case 500 refers to an Internal Server Error. A simple way to handle http status codes is to just check if the request was successful and not handle every single status code. :)

if(status == 200){
    // Request Success
}else{
    // Request Failed
}