API Override - Customized response fails to appear for PUT actions in related data
tannerwelsh opened this issue · comments
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:
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
Hi @tannerwelsh, thanks for your feedback.
Is this ticket really about Smart Actions? Isn't it a "native" action?
Can you detail your usecase (and schema behind this usecase)?
Thanks for the help.
Hi @arnaudbesnier - you're absolutely right, this is a "native" action that I've overridden, not a "smart" action.
Use case is that I need to be able to edit items in a smart field of related data, and the default form created includes fields that are read-only, as well as virtual fields, and thus I need to be able to selectively update the document. Ideally I'd be able to customize that edit form more explicitly, but that's a separate story.
Is there any way to customize the messages returned for a "native" action that has been overwritten? If not, then this issue is moot.
Hi @tannerwelsh,
So far, you can't do that for native actions.
That's why I consider this as a feature request.
Unfortunately, I cannot provide any ETA for this. And I feel that this is not something we'll work on soon.
Sounds good, thanks for letting me know @arnaudbesnier. Feel free to close this issue if you want to track the feature request elsewhere.