我有一个 Node 程序,如果出现错误,需要发送错误消息, 这可行,但是我想在消息中添加一个链接。
类似的东西
Something went wrong and we cannot open your application.
Follow this tutorial to proceed.
本教程将是一个链接,例如https://nodejs.org/en/about/
我怎样才能做到这一点?
...
} 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.'
)
}
我通过像res.send
这样的 express 发送数据
app.get('/', async function (req, res) {
try {
const url = await invokeApp()
} catch (e) {
res.send(e.message)
}
})
更新
在尝试下面的建议时,我能够获取链接,但消息顺序已更改,知道如何修复它吗?
} 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.'
)
}
最佳答案
试试这个:
...
} 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.')
}
您可以使用res.send
带有 html 字符串——即 res.send('<p> html </p>')
- 并在另一边处理。
关于javascript - Node 快速返回带有链接的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63136136/