exception2
v0.0.4
Published
```typescript import { Exception2, exception2Types } from 'exception2';
Readme
Throwing
import { Exception2, exception2Types } from 'exception2';
throw new Exception2({
// exceptionKey is camelCase string to strictly and
// easily identify exception and to use as i18n key
exceptionKey: 'someKey1',
// data is object to pass everything you want to pass
// to catcher or to frontend from backend
data: { userIdHavingThisError: 1 },
// Optional property to map into http error codes when needed
exceptionTypeKey: exception2Types.validation,
});When using on backend and requiring defining http status of error, use optional exceptionTypeKey and httpStatusByExceptionType for mapping to https codes
Handling
You want to know if caught exception is exception2
When catching within same application use instanceOf Exception2
When getting it serialized from another api use isSerializedException
When you catch unknown exception use getCaughtExceptionMessage to either read its message or exceptionKey
If you want to unify unknown caught exception to Exception2, use toException. It will put the passed exception to data.
