RealDevSquad / RealDevSquad/website-backend

Pattern refactor

Open
#128 2 comments 0 reactions 1 assignee View on GitHub

@Khanjan04 is already working on this.

Since Jan 17, 2021.

good first issue refactor
Dominant language
JavaScript
Stars
74
Forks
276
Avg merge
1d 26m
Merged PRs (30d)
14

Description

Now:

const addNewTask = async (req, res) => {
 try {
     // LOGIC HERE
  } catch (err) {
    logger.error(`Error while fetching tasks ${err}`)
    return res.boom.serverUnavailable('Something went wrong please contact admin')
  }
}
}

const fetchTasks = async (req, res) => {
  try {
     // LOGIC HERE
  } catch (err) {
    logger.error(`Error while fetching tasks ${err}`)
    return res.boom.serverUnavailable('Something went wrong please contact admin')
  }
}

module.exports = {
  addNewTask,
  fetchTasks
}

Refactor:

// runtimeErrorHandler.js
const _addNewTask = async (req, res) => {
   // LOGIC HERE
}

const addNewTask = runtimeErrorHandler(_addNewTask, [optional 'custom error message]');
 
module.exports = {
  addNewTask,
  fetchTasks
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.