Patch #24323

Improve exceptions handling

Added by Pavel Rosický over 5 years ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:REST API
Target version:-

Description

Hello,
I would like to improve REST api. Now you can use this request and specify requested format directly in the url like this:

    $.ajax('/myurl.json', {
      method: 'POST',
      data: {}
...

but I expect this should work aswell

    $.ajax('/myurl', {
      method: 'POST',
      data: {}
      dataType: 'json'
...

but the server responds with text (plain) 500 internal error - no builder for format

http://api.jquery.com/jQuery.ajax/
dataType (default: Intelligent Guess (xml, json, script, or html))
Type: String
The type of data that you're expecting back from the server.

before
status: 500
body: -
format: plain

patched
status: 422
body: {"errors":[{"error": "Something is wrong"}]}
format: json

I have also improved the render_error method, now you'll get a proper error message according to the format you're asking for. For instance an api request (post /something.json):
before:
status: 422
body: -

patched:
status: 422
body: {"errors":[{"error": "Something is wrong"}]}

Environment:
Redmine version 3.3.1.devel
Ruby version 2.1.5-p273 (2014-11-13) [x64-mingw32]
Rails version 4.2.7.1
Environment production
Database adapter Mysql2
SCM:
Git 2.10.1
Filesystem
Redmine plugins:
no plugin installed

application_controller.rb.patch Magnifier (641 Bytes) Pavel Rosický, 2016-11-11 11:06

builders.rb.patch Magnifier (501 Bytes) Pavel Rosický, 2016-11-11 11:06

Also available in: Atom PDF