S
S
superivankorolev2016-04-02 16:25:38
Node.js
superivankorolev, 2016-04-02 16:25:38

How to catch an error (error decode url) in express?

URIError: Failed to decode param 'CZito%tS'
at decodeURIComponent (native)
at decode_param (/var/app/node_modules/express/lib/router/layer.js:167:12
) violates the URL standard (the percent symbol will be entered incorrectly), then it receives such an error. And this is unacceptable for the user to see what files are on the server, and so on.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
superivankorolev, 2016-04-02
@superivankorolev

something like this =) I decided myself.

app.use( (req, res, next) => {
    var err = null;
    try { decodeURIComponent(req.path); }
    catch(e) { err = e;}
    if (err){
        console.log(err, req.path);
        res.send('400 Bad Request');    
    }else next();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question