Node express return message with link

Viewed 527

I've node program which in case of error needs to send error message , this works, however I want to add to the message also a link.

something like

Something went wrong and we cannot open your application.
Follow this tutorial to proceed.

And the this tutorial will be a link e.g. https://nodejs.org/en/about/

How can I do that?

...
    } catch (e) {
        throw new Error('Something went wrong and we cannot open your application.Follow <a href="https://nodejs.org/en/about/">this</a> tutorial to proceed.'
        )
    }

And I send the data via express like res.send

app.get('/', async function (req, res) {

    try {
        const url = await invokeApp()

    } catch (e) {
        res.send(e.message)
    }

})

update

while trying the suggestion below I able to get the link but the messege order was changed, any idea how to fix it ?

    } catch (e) {
        throw new Error('Something went wrong and we cannot open your application.Follow <a href="https://nodejs.org/en/about/">this</a> tutorial to proceed.'
        )
    }

enter image description here

2 Answers

try this:

...
    } catch (e) {
        throw new Error('Something went wrong and we cannot open your application. Follow <a href="https://nodejs.org/en/about/">this</a> tutorial to proceed.')
    }

You can use res.send with html string -- i.e res.send('<p> html </p>') - and deal with on the other side.

Try this

res.json({ err : e.message , link : "error/url"})

and if error comes you could acces url from this object and display the link in front end.

Related