For first I use this solution - http://www.yiiframework.com/doc-2.0/guide-rest-error-handling.html But, I want to customize two types error.
- When model validation wrong.
- When something wrong (Exceptiin)
If model validation wrong i get response, like that:
{
"success": false,
"data": [
{
"field": "country_id",
"message": "Country Id cannot be blank."
},
{
"field": "currency_id",
"message": "Currency Id cannot be blank."
},
{
"field": "originator_id",
"message": "Originator Id cannot be blank."
}
]
}
But i want like that:
{
"success": false,
"data": [
"errors": [
{
"field": "country_id",
"message": "Country Id cannot be blank."
},
{
"field": "currency_id",
"message": "Currency Id cannot be blank."
},
{
"field": "originator_id",
"message": "Originator Id cannot be blank."
}
]
]
}
Second type error i get
{
"success": false,
"data": {
"name": "Exception",
"message": "Invalid request arguments",
"code": 0,
"type": "yii\\base\\InvalidParamException",
]
}
}
But i Want:
{
"success": false,
"data": {
"errors" : 1, <----------------
"name": "Exception",
"message": "Invalid request arguments",
"code": 0,
"type": "yii\\base\\InvalidParamException",
]
}
}
Because in anyway user get 200 Response and they don know about error or mistake.