0

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?

1 Answer 1

1

In your config/main.php response component:

'response' => [
  'format' => yii\web\Response::FORMAT_JSON
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.