Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error filtering #8

Open
timwis opened this issue Aug 16, 2019 · 0 comments
Open

Improve error filtering #8

timwis opened this issue Aug 16, 2019 · 0 comments

Comments

@timwis
Copy link
Contributor

timwis commented Aug 16, 2019

At the moment, server.js has several try/catch blocks that do "error filtering":

try {
  const data = await getData()
  ctx.body = data
} catch (err) {
  if (err.message.startsWith('invalid tree ref')) {
    ctx.throw(404, 'unknown ref')
  } else {
    throw err
  }
}

There's some redundancy there and it decreases readability. There has to be a better way. I think it is to have lib/GitSheets.js throw custom errors, e.g. NotFoundError, and have server.js map these to status codes in a single place (the error handler function).

That still leaves the errors that originate beneath lib/GitSheets.js (from hologit, gitsheets, or git). I expect we'll still have to do some string matching on that, but it can be at the lib level rather than the server level. So we'll essentially translate invalid tree ref to NotFoundError, and the server and CLI just need to decide what to do with a NotFoundError.

We can use create-error for custom errors or probably just do it manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant