error page with static content

5 views
Skip to first unread message

Philipp Kraus

unread,
Aug 16, 2015, 11:26:19 AM8/16/15
to Express
Hello,

I'm using Express 4 and try to use error pages e.g. for 404 & 500 errors and static content. If I call http://localhost:9090/notfound (notfound does not exists) the error page is shown, but CSS and static Javascript files or images are not send. My template engine is Jade.
My code is defined as:

The static content:

po_application = express();
po_application.use('/jquery.js', express.static( require.resolve('jquery') ) );
po_application.use(express.static( lc_staticdir ));

The error handler code is defined after the static content with:

    var lf_error = function( po_request, po_resource, pn_number, pc_message ) {
        var lo_error = {
            'errormessage' : po_request.i18n.__('global_error', po_request.url, pc_message || ''),
            'errorcode'    : pn_number || 500
        };
        po_resource.status(lo_error.errorcode);

        // handle different result types
        if (po_request.accepts('html'))
        {
            po_resource.render( 'error', lo_error );
            return;
        }

        if (po_request.accepts('json'))
        {
            po_resource.send( lo_error );
            return;
        }

        po_resource.type('txt').send( lo_error.errormessage );
    }


    po_application.use(function(po_request, po_resource, po_next ) {
        lf_error(po_request, po_resource, 404);
    });

    po_application.use(function(po_error, po_request, po_resource, po_next ) {
        lf_error(po_request, po_resource, 500, po_error.message);
    });

Chrome reports on a non-existing page:

localhost/:1 GET http://localhost:9090/main.js 404 (Not Found)

all three files exists within the static content and the error is also reported on all other Jade templates. If I remove the two error handlers, the normale templates works well.

I would like to define an own error Jade template for all errors within my application (exception throwing with a 500 error and non-existing files with 404). How can I do this in a correct way?

Thanks

Phil
Reply all
Reply to author
Forward
0 new messages