Throw a json response?
See original GitHub issueThis is not an issue, rather a discussion.
Is there a way to reduce this part (<--
) of the code?
if (action === "save") {
const result = getParams<SaveActionType>(formData, saveSchema);
if (!result.success) { // <--
return json(result.errors, { status: 400 }); // <--
} // <--
const { id, ...values } = result.data;
await updateExam(id, values);
}
In fact, my real question is: does a throw in getParams
could be captured and transformed, in some way, in the returned json via the CatchBoundary
?
If I have several actions, it seems repetitive. Perhaps can it be improved? āĀ Iām fully aware that at some point, things need to be written, just asking ;D
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How can I pass JSON body of Fetch response to Throw Error ...
I am NOT trying to convert an object into a JSON string. I'm using SweetAlert2 with Laravel. throw error(response => response.json()) swal({Ā ...
Read more >Response.json() - Web APIs - MDN Web Docs
The json() method of the Response interface takes a Response stream and reads it to completion. It returns a promise which resolves with...
Read more >JSON error handling
In cases where a JavaScript Object Notation (JSON) transaction fails, the API Gateway can use a JSON error to convey error information to...
Read more >How to check if an API error response is JSON or not with ...
If the response is ok , I use the Response.json() method to get my data. Otherwise, I throw the response to catch() the...
Read more >Error while parsing JSON Response in REST API Post call
I have copied and pasted the REST Request and Response JSON definitions into the Request and Response text boxes provided by OS REST...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No. This would actually go to
ErrorBoundary
. Like Iāve said before, I think itās better to return form validation errors, so you can display the messages.This is if you want to fail fastā¦ but Iām not a fan of throwing Error, since that should be reserved for unexpected errors.
Interesting. To be used in combination with
CatchBoundary
I suppose? But it means you canāt give feedbacks in a form input?Still, handy to have this version! š