How to read body from http 500 response

335 views
Skip to first unread message

vcf...@gmail.com

unread,
Jul 15, 2016, 2:39:08 AM7/15/16
to DukeScript
Hi, 

I need to read a response from an API. For successful response, it returns something like this:

HTTP status code: 200
Content Type: application/json
Body:
{
"records":[{object1}, {object2}]
}


For error case:

HTTP status code: 500
Content Type: application/json
Body:
{
"code":"1234",
"message":"reason"
}

How to use DukeScript to read the error body?

Regards,
Victor

Jaroslav Tulach

unread,
Jul 16, 2016, 3:33:18 AM7/16/16
to vcf...@gmail.com, DukeScript
Wow, what an interesting request! I've never imagined somebody would like to read body in case of error.

First of all thanks for your will to use DukeScript (and my HTML+Java API, http://wiki.netbeans.org/Html4Java).

I am afraid that to achieve what you want you need to play directly with the source of HTML+Java API and modify it to suite your needs. Can you follow the steps outlined in http://wiki.netbeans.org/Html4Java and compile&test the current version? Then you could modify the source to simulate what you need, then recompile and retest.

I would start at two locations:
- modify the test server to return 500 from time to time: http://hg.netbeans.org/html4j/file/031e46d048d8/ko4j/src/test/java/org/netbeans/html/ko4j/DynamicHTTP.java#l102
It should be relatively easy to work with the project from inside of any Maven-ready IDE. I know that NetBeans IDE works well and allows you to execute single test and even debug it, which may speed your experiments up. Once you have what you need, send us a patch. I'll do my best to include it into the next version of HTML+Java API then.

Good luck and thanks once again for giving DukeScript a try!
-jt


 

--
You received this message because you are subscribed to the Google Groups "DukeScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dukescript+...@googlegroups.com.
Visit this group at https://groups.google.com/group/dukescript.
To view this discussion on the web visit https://groups.google.com/d/msgid/dukescript/e244da68-f003-4912-8666-7b38e30d43e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages