Modelling and handling failure states
There are unexpected and expected errors. Unexpected errors should be modelled as JavaScript Error types. Expected errors should be modelled as custom objects that are specific to the domain where the error occured. A function that can have expected errors should return either the successful value or the expected error.