Skip to content
  • Projects
  • Groups
  • Snippets
  • Help

node / oss-middle-server

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • oss-middle-server
  • src
  • middleware
  • ErrorRoutesCatch.js
  • liimin's avatar
    create · b9ce0e9d
    liimin committed Aug 05, 2019
    b9ce0e9d Browse Files
ErrorRoutesCatch.js 469 Bytes
RawBlameHistoryPermalink
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
module.exports = function () {
  return function (ctx, next) {
    return next().catch((err) => {
      switch (err.status) {
        case 401:
          ctx.status = 200
          ctx.body = {
            status: 401,
            result: {
              err: 'Authentication Error',
              errInfo: 'Protected resource, use Authorization header to get access.'
            }
          }
          break
        default:
          throw err
      }
    })
  }
}