Throw a JSON exception?

Hi,

Trying to implement a protocol, and in the spec, I have to return json error message.

I tried in this commit:

(I tried to copy the logic from provisionning_api app)

But the result is still html:

Nextcloud
Internal Server Error
The server was unable to complete your request.

If this happens again, please send the technical details below to the server administrator.

More details can be found in the server log.

Technical details
Remote Address: 192.168.21.4
Request ID: G8zPDUrKkMVeud3lgRUg
OCA\SCIMServiceProvider\Exceptions\SCIMException
404
{"schemas":["urn:ietf:params:scim:api:messages:2.0:Error"],"detail":"User not found","scimType":"","status":404}
/var/www/html/apps-extra/scimserviceprovider/lib/Controller/ASCIMUser.php
88

Trace
#0 /var/www/html/apps-extra/scimserviceprovider/lib/Controller/UserController.php(142): OCA\SCIMServiceProvider\Controller\ASCIMUser->getSCIMUser('testfewvwev')
#1 /var/www/html/lib/private/AppFramework/Http/Dispatcher.php(217): OCA\SCIMServiceProvider\Controller\UserController->show('testfewvwev')
#2 /var/www/html/lib/private/AppFramework/Http/Dispatcher.php(126): OC\AppFramework\Http\Dispatcher->executeController(Object(OCA\SCIMServiceProvider\Controller\UserController), 'show')
...

Do you have an idea, or some snippet in some repo to throw json exception?

Thanks for your help!

Maybe inspiration of other apps can help you:
https://github.com/nextcloud/spreed/blob/master/lib/Middleware/InjectionMiddleware.php#L246

1 Like

If I understand correctly a json exception is just a json response of a certain format and not to be confused with php exceptions and similar.

I don’t see anything obvious that is wrong with your implementation.

You can also see mail/ErrorMiddleware.php at main · nextcloud/mail · GitHub as another working example.

1 Like