Skip to content

API Override - Customized response fails to appear for PUT actions in related data #167

Description

@tannerwelsh

Expected behavior

When editing the content of a record in a "related data" set that triggers a custom action, I would expect the custom response from that action to be rendered as a message in the same manner as is specified at https://doc.forestadmin.com/developer-guide/express-mongoose.html#customizing-response.

Actual behavior

The custom message works for POST requests with the same set of related data, but not for PUT requests. When sending a PUT request from a related data edit form, it has the following behavior:

  • When receiving a 400 response, the UI "blinks" and shows no message.
  • When receiving a 200 response, the UI displays a brief generic "success" message, and then returns to the related data list page.

Failure Logs

For Valid Requests w/ Custom 200 Response

Here's an example valid update PUT request and the custom response

Request URL: http://localhost:5000/forest/Survey/5ada0e46c38fd399899c9dfa/relationships/questionList/18
Request Method: PUT
Status Code: 200 OK
Remote Address: [::1]:5000
Referrer Policy: no-referrer-when-downgrade

RESPONSE HEADERS

Access-Control-Allow-Origin: http://app.forestadmin.com
Connection: keep-alive
Content-Length: 42
Content-Type: application/vnd.api+json; charset=utf-8
Date: Fri, 27 Apr 2018 15:18:09 GMT
ETag: W/"2a-Aqil8IhIAZRpmsttb3yXbM5+PxI"
Vary: Origin
X-Powered-By: Express

REQUEST HEADERS

Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Authorization: Bearer [hidden]
Connection: keep-alive
Content-Length: 114
Content-Type: application/json; charset=UTF-8
Host: localhost:5000
Origin: http://app.forestadmin.com
Referer: http://app.forestadmin.com/23689/data/857897/index/record/857897/5ada0e46c38fd399899c9dfa/has-many-embedded/13974064/edit/18
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36

REQUEST PAYLOAD

{"data":{"attributes":{"question_id":"5ad7d3c623a9b5d7aec16c30","questionName":"VideoFeedback","sortOrder":"22"}}}

RESPONSE

{"success":"Survey question list updated"}

Instead of displaying the message "Survey question list updated", the message displayed is:

screen shot 2018-04-27 at 10 14 00 am

Which is just the default message for this related data type.

For Invalid/Failed Requests w/ Custom 400 Response

When sending a failed request such as the following...

Request URL: http://localhost:5000/forest/Survey/5ada0e46c38fd399899c9dfa/relationships/questionList/18
Request Method: PUT
Status Code: 400 Bad Request
Remote Address: [::1]:5000
Referrer Policy: no-referrer-when-downgrade

RESPONSE
{"error":"Survey validation failed: questions.18.sortOrder: Path `sortOrder` (-22) is less than minimum allowed value (0)."}

...no message at all is shown. The UI flickers and stays on the same view.

Context

Using Mongo 3.6 with forest-express-mongoose package.

  • Package Version: 2.8.2
  • Express Version: 4.16.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions