Commit 6da59abe authored by Jérôme Chauveau's avatar Jérôme Chauveau
Browse files

rm simple-error func

parent 3d4fdb39
Loading
Loading
Loading
Loading
+16 −21
Changes for src/main/core/errors.xqm: 16 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -32,24 +32,6 @@ function errors:not-found($message, $lang as xs:string){

};

(:~
 : Returns 404 error page
 : @return HTML page
 :)
declare
function errors:simple-error($code as xs:QName, $desc as xs:string, $line as xs:integer){
  let $message := string-join(($code,  $desc, 'line ' || $line),', ')
  return
  (<rest:response>
    <http:response status="500">
      <http:header name="Content-Language" value="en"/>
      <http:header name="Content-Type" value="text/html; charset=utf-8"/>
    </http:response>
  </rest:response>,
  admin:write-log($message),
  'MaX Error : ' || $message)
};


(:~
 : Returns a 500 error page
@@ -61,12 +43,13 @@ declare
function errors:error($code as xs:QName, $desc as xs:string, $line as xs:integer, $lang as xs:string) as element(html){
  let $tmpl := templating:template-file('error.html')
  let $detail := if(conf:is-dev-mode()) then string-join(($code,  $desc, 'line ' || $line),', ') else ''
  let $render := templating:render(
  let $render := if($tmpl) then templating:render(
    'error.html',
    map{'title': templating:translate('server-error', $lang),'content' : $detail, 'lang' : $lang})
    else errors:default-error-render($detail)
  return
  (<rest:response>
    <http:response status="500">
    <http:response status="500">if($tmpl)
      <http:header name="Content-Language" value="en"/>
      <http:header name="Content-Type" value="text/html; charset=utf-8"/>
    </http:response>
@@ -94,7 +77,7 @@ function errors:errors($messages, $lang as xs:string?) as element(html){
    then templating:render(
    'error.html',
    map{'title': templating:translate('server-error', $lang),'content' : $detail, 'lang' : $lang})
    else fn:string-join($messages, ' / ')
    else errors:default-error-render(fn:string-join($messages, ' / '))
  return(
  <rest:response>
    <http:response status="500">
@@ -105,3 +88,15 @@ function errors:errors($messages, $lang as xs:string?) as element(html){
  admin:write-log(fn:string-join($messages, ' / ')),
  $render)
};


declare %private function errors:default-error-render($message) as element(html){
    <html>
        <head>
            <title>MaX Error</title>
       </head>
       <body>
        <p>{message}</p>
       </body>
    </html>
};
 No newline at end of file
+13 −5
Changes for src/main/core/routes.xqm: 13 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -84,8 +84,8 @@ function routes:page($lang as xs:string, $path as xs:string){
        }
        catch file:not-found {errors:not-found($err:code || ' - ' ||$err:description, $lang)}
        catch err:FODC0002 {errors:not-found($err:code || ' - ' ||$err:description, $lang)}
        catch err:max-templating {errors:simple-error($err:code, $err:description, $err:line-number)}
        catch err:max-conf {errors:simple-error($err:code, $err:description, $err:line-number)}
        catch err:max-templating {errors:error($err:code, $err:description, $err:line-number, $lang)}
        catch err:max-conf {errors:error($err:code, $err:description, $err:line-number, $lang)}
};


@@ -168,7 +168,7 @@ declare
%rest:GET
%output:method("html")
%output:html-version('5')
%rest:path("/max-infos.html")
%rest:path("/about.html")
function routes:max-infos(){
    if(conf:is-dev-mode())
    then
@@ -217,6 +217,12 @@ function routes:max-infos(){
                {routes:list()}
            </section>
            <section>
                <h2>Documentation</h2>
                <div>
                    <a href="/doc/functions.html">Consulter l'API XQuery de MaX</a>
                </div>
            </section>
            <!--<section>
                <h2>Modules</h2>
                <ul>
                {
@@ -224,7 +230,7 @@ function routes:max-infos(){
                    return <li>{$package}<strong>{string($package/@*:name)}</strong> : {string($package/@*:version)}</li>
                }
                </ul>
            </section>
            </section>-->
        </body>
    </html>
    else errors:not-found('', $conf:default-lang)
@@ -283,6 +289,8 @@ declare
%output:method("html")
%rest:path("/doc/functions.html")
function routes:functions-documentation(){
    if(conf:is-dev-mode())
    then
        let $toIgnore := ('globals.xqm','markdown.xqm')
        let $packageDoc := doc(conf:get-package-file-path())
        let $xqDocs := <div>{for $module in $packageDoc//*:xquery/*:file where not(string($module) = $toIgnore)
@@ -291,5 +299,5 @@ function routes:functions-documentation(){
                    </div>

        return xslt:transform($xqDocs, doc(conf:get-resources-path()  || 'doc-2-html.xsl'))

    else errors:not-found('', $conf:default-lang)
};