Skip to content

Improve error filtering #8

Open
@timwis

Description

@timwis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions