basex
basex copied to clipboard
RESTXQ: User-friendly error messages
Values of an HTTP request will be assigned to the parameters of the invoked function. If the assignment fails, the returned error message should be more intuitive:
- Right now, it indicates what went wrong during the variable assignment in XQuery.
- The returned message should rather indicate how the request can be rewritten by the client to be successfully processed.
Examples
RESTXQ function:
declare %rest:path("page") %rest:query-param("param", "{$p}")
function page:x($p as xs:string) { };
HTTP Request: http://localhost/page
Returned error:
Stopped at F:/webapp/x.xqm, 6/10:
[XPTY0004] Cannot convert empty-sequence() to xs:string: ().
Better alternatives:
- Query parameter "param" must be of type xs:string, found: () as empty-sequence().
- Query parameter "param" must be of type xs:string. Found: ().
- Query parameter "param" cannot be converted to xs:string: ().
- "param" could not be assigned to $p: empty-sequence() found, xs:string expected.
RESTXQ function:
declare %rest:path("browse/{$n}")
function page:x($n as xs:integer) { };
HTTP Request: http://localhost/browse/INVALID
Returned error:
Stopped at F:/webapp/x.xqm, 5/10:
[FORG0001] Cannot convert xs:untypedAtomic to xs:integer: "INVALID".
Better alternatives:
- Path segment must be of type xs:integer, found: INVALID as xs:untypedAtomic.
- Path segment must be of type xs:integer. Found: INVALID.
- Path segment cannot be converted to xs:integer: INVALID.
- Path segment could not be assigned to $n: xs:untypedAtomic found, xs:integer expected.
A similar observation applies to requests for which more than one endpoint is found:
RESTXQ function:
declare %rest:path("a") function page:a1() { };
declare %rest:path("a") function page:a2() { };
HTTP Request: http://localhost/browse/a
Returned error:
Stopped at F:/webapp/x.xqm, 5/10:
[basex:restxq] Several functions found for path "b":
- page:x
- page:z
It might not be necessary to return information on the XQuery code.