Custom content for http error responses

Started by Jeff Wilder, March 09, 2019, 02:18:01 PM

Previous topic - Next topic

martinp

Quote from: Mike King on March 10, 2021, 10:20:15 AMDirk

Just an FWIW: In PxPlus 2021 due in May we have added a new global variable %Exit_include_html which you can set when you set %Exit_code to indicate you want the output you have placed in %PRINT_FN to be used along with the status code; something like this:

[tt]  json$["errors.1.status"]="400"
  json$["errors.1.code"]="4077"
  json$["errors.1.title"]="INVALID FORMAT"
  json$["errors.1.detail"]="invalid query paramete"
  json$["errors.1.source.parameter"]="date"
  json$["errors.1.source.example"]="2019-03-09"
!
  %content_type$="application/json"
  Write Record (%print_fn) DIM(LIST EDIT json${ALL})
!
  %exit_code=400
  %exit_include_html=1
[/tt]


We have this exact program setup on at https://www.pvxplus.com/march10.pxp so you can see the output which was based on the desired output that originally started this thread.

As for other REST style services our web services, available since PxPlus 2014, can be used to provide charts, reports, lists, and other data on demand -- suitable for use with JavaScript or other applications.  For details see:  https://manual.pvxplus.com/page/PxPlus%20Web%20Services.htm



Hey Mike:)  Just testing this everythings working except my pvxplus web server (not ezweb/apache) does not return the content_Type "application/json" when I use LET %EXIT_INCLUDE_HTML=1  it reverts back to "Text/Html" not end of world.