SuccessModel.js
class SuccessModel {
constructor(data) {
this.errno = 0
if (data != null) {
this.data = data
}
}
}
module.exports = SuccessModel
ctx.body = new SuccessModel(newAddress)
------------------------------
ErrorModel.js
class ErrorModel {
constructor(errno = -1, message = 'error') {
this.errno = errno,
this.message = message
}
}
module.exports = ErrorModel
ctx.body = new ErrorModel(10004, `创建地址失败`)
---------------------------------------------------------
方便调用
index.js
const SuccessModel = require('./SuccessModel')
const ErrorModel = require('./ErrorModel')
module.exports = {
SuccessModel,
ErrorModel
}