Improve json 401 exception

Returns an object with ``code`` and ``message`` fields instead of a string.