isomerpages / isomercms-backend

A static website builder and host for the Singapore Government
5 stars 1 forks source link

refactor(errors): migrate from js to ts #804

Closed seaerchin closed 1 year ago

seaerchin commented 1 year ago

Problem

This PR migrates errors from js -> ts, under the new proposal (see here).

Closes IS-211

Solution

  1. add code property to the base error - will be inherited by our errors so it's less onerous on devs
  2. change errors from js -> ts
    • this was done by renaming the file, then changing the super call to take an object. only BadRequestError has a change
  3. add LegacyErrors - should use as a marker. when can't find in codebase, we know migration is done
  4. stricter type enforcement on our error types using template literal types + const obj - we want devs to go through our constants to get the values or pass only the correct values. if we don't use as const/template literal, this enforcement isn't done as the type is string
  5. add a very simple test spec for errors - just testing the code property works as expected