HttpBasicAuth custom response Unauthorized

Hi all, in my Rest Api i have HttpBasicAuth that works fine.

Now i want to customize the response if the accesstoken is wrong.

I want to change the default:




{

    "name": "Unauthorized",

    "message": "Your request was made with invalid credentials.",

    "code": 0,

    "status": 401,

    "type": "yii\\web\\UnauthorizedHttpException"

}



with something like:




{

    "token": *the token sent*,

    "message": "Invalid Token."

}



can anyone tell me the right way? Thank’s