过去 3 年我一直在做 Swift 开发,最近切换到打字稿。
在 Swift 中,NSError 类型的错误为我们提供了一些属性。
在 JavaScript 中,任何错误都是错误的。
为什么有任何错误?如何创建具有某些属性的自定义类并在整个项目中使用它?
try {
const decodedResult = decode(token)
// Adding userId in the headers to use in the models.
req.headers.userId = decodedResult.paylod.id
next()
} catch (error) {
console.log(error)
new errorController(401, 'Authentication required.', res)
}
现在这里的错误对象是 any 类型。我希望它是强类型的。
犯罪嫌疑人X
相关分类