Hi Bridger,
As your query will either return an empty sequence (in the case of success) or a string (in the case of an error), you’ll need to use xs:string? as return type:
declare function local:grab( $url as xs:string, $path as xs:string, $fname as xs:string ) as xs:string? { ...
Hope this helps, cheers, Christian
let $req := http:send-request(<http:request method="get"/>, $url) return if (head($req)/@status = "200") then file:write($path || $fname, tail($req), map { "method": "xml" }) else ("something went wrong!") };
but I've noticed that in version 9.4.3 this returns an XPTY error: Stopped at /home/bridger/bin/basex-src/basex-943-xpty0004-error.xq, 1/18: [XPTY0004] Cannot promote xs:string* to document-node(): (let $req_7 := http:send-request(<http:request method="get"/>, "https://dpla.lib.utk.edu/repox/OAIHa.... While this could be a bug, should I be writing this kind of local function differently? Or could I improve my typing on it? Thanks very much for any advice or insights you can provide. Best, Bridger