Sequentially resolve promises using Node.js

Controller:

const CategoryError = require('./errors')
const catchError = require('./catch-error')

exports.myFunction = (req, res, next) => {
  Category.findOne({
    name: req.params.id
  })
    .then(category => {
      if (!category) {
        throw new CategoryError().__404__()
      }
      return Article.find({ category: category._id })
    })
    .then(articles => {
      return res.status(200).json({ articles: articles })
    })
    .catch(err => {
      return catchError(res, err)
    })
}

Error Handler:

const ErrorParent = require('.error-parent')

const catchError = (res, err) => {
  if (err instanceof ErrorParent) {
    return res.status(err.status).json({
      message: err
    })
  } else {
    console.log(err)
    return res.status(500).json({
      message: 'INTERNAL_ERROR'
    })
  }
}

module.exports = catchError
class ErrorParent extends Error {
  constructor () {
    super('')
    this.name = this.constructor.name
    Error.captureStackTrace(this, this.constructor)
  }
  getError () {
    return this.error
  }
  __400__ (error = "BAD_REQUEST") {
    this.error = error
    this.status = 400
    return this
  }
  __401__ (error = "UNAUTHORIZED") {
    this.error = error
    this.status = 401
    return this
  }
  __403__ (error = "FORBIDDEN") {
    this.error = error
    this.status = 403
    return this
  }
  __404__ (error = "NOT_FOUND") {
    this.error = error
    this.status = 404
    return this
  }
  __409__ (error = "CONFLICT") {
    this.error = error
    this.status = 409
    return this
  }
}
module.exports = ErrorParent

const ErrorParent= require('error-parent')
class CategoryError extends ErrorParent {
  
}
module.exports = CategoryError