Using Ajax, we sometimes have internal errors in the PHP code, making Yii spit out 500. This message is always in HTML, not JSON. Is it possible to make it JSON instead, for certain controller methods?
Something like this (but not manually):
header('Content-Type: application/json');
http_response_code(405);
die(json_encode(['message' => 'Could not save label set.']));