Open xutl opened 7 years ago
Do you have an ApiController
or a UsersController
in an api
module? If the latter your app might not know about the fact that you wanted an API page, when you're serving mixed content.
As @schmunk42 said, in order to respond 404 in this case, custom error handler is needed. I think it's a good idea to document it. Pretty standard use case.
This usecase has not documented yet.
it is handled in this action
'errorHandler' => [
'errorAction' => 'site/error',
],
@phpyii have you try in rest application? @samdark so you mean custom error handler is not available until 2.0.16?
custom error handler does already work, the only thing that is missing in this issue is documentation.
I've tried all kinds of "solutions" for this problem and none of them work for me. My current setup:
backend
contains a module called api
:
'modules' => [
'api' => [
'class' => backend\modules\api\Module::class,
],
],
All existing actions work perfectly fine.
However, when I make a request to a non-existing action in this module (e.g. /api/index/no-such-action
), I get the default site/error
HTML page! It even ignores the Accept
header, which is set to application/json
.
Module#init()
is not even called, thus anything I try to attempt to do there or in the controller is useless.
How am I supposed to work around this? I don't see a non-hackish way to fix this.
Issue moved to https://github.com/yiisoft/yii2-rest/issues/13
What steps will reproduce the problem?
return 200 ok
return 404 this is normal
What is the expected result?
Returns a formatted xml or json.
What do you get instead?
Additional info