module namespace _ = 'app/error-reporting';
import module namespace cm = "app/cm" at "common.xqm";


declare 
  %rest:error("*")
  %rest:error-param("code", "{$code}")
  %rest:error-param("description", "{$description}")
  %rest:error-param("value", "{$value}")
  %rest:error-param("module", "{$module}")
  %rest:error-param("line-number", "{$line-number}")
  %rest:error-param("column-number","{$column-number}")
  %rest:error-param("additional", "{$additional}")
function _:error($code,$description,$value,
                 $module,$line-number,$column-number,$additional) {
 let $err:=map{"code":$code, "description":$description,
               "value": _:format($value),  "module": $module, 
               "line-number": $line-number, "column-number": $column-number,
               "additional": _:format($additional)}
  return  cm:htmx2("error.htm", $err)             
}; 

declare function _:format($item)
as xs:string{
 serialize($item,map{"method":"basex"})
};