Project

General

Profile

Actions

Patch #24323

open

Improve exceptions handling

Added by Pavel Rosický over 7 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
REST API
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

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

Files

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

No data to display

Actions

Also available in: Atom PDF