0.0.3 • Published 4 years ago

akos-handcustomcode v0.0.3

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

akos-handCustomCode

hand custom formatting return

introduce

  1. option.ResponseCode The custom code you want.
    // default
       {
         Success: 200,
         Unauthorized: 401,
         Invalid: 403,
         NotFound: 404,
         InternalError: 500,
     }
     
  2. Provide method
  • throwCodeError
  • setCodeError
  • setBodyResult
  • setBodyContent

  1. for example
  async userInfo() {
        const ctx = this.ctx;
        //  a method to get user from mysql
        const user = await ctx.service.user.getInfo()
        ctx.setBodyContent(200, user)
    }

you will get the result

{
    code: 200,
    result: {
        //....userInfo....
    }
}