I have created a modules say Api using gii in my yii2-advanced application and API working with access token in header Authorization, but in case of wrong access token or no access token the API return 401 page html.
How to handle error/exception in yii2 API so that I can format response data in json?