-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(init): add standard errors and methods
- Loading branch information
1 parent
70c535a
commit 4b8a95f
Showing
14 changed files
with
244 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { stage, Stage } from './src/utils/environment'; | ||
|
||
/** | ||
* sanity check that unit tests are only run in 'test' environment | ||
* - if they are run in prod environment, we could load a bunch of junk data into our prod databases, which would be no bueno | ||
*/ | ||
if (stage !== Stage.TEST && process.env.I_KNOW_WHAT_IM_DOING !== 'true') | ||
if ( | ||
(process.env.NODE_ENV !== 'test' || process.env.STAGE) && | ||
process.env.I_KNOW_WHAT_IM_DOING !== 'true' | ||
) | ||
throw new Error(`unit-test is not targeting stage 'test'`); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BadRequestError } from './BadRequestError'; | ||
|
||
describe('BadRequestError', () => { | ||
it('should produce a helpful, observable error message', () => { | ||
const error = new BadRequestError('no tires on the vehicle', { | ||
tires: [], | ||
}); | ||
expect(error).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { HelpfulError } from './HelpfulError'; | ||
|
||
/** | ||
* BadRequestError errors are used to explicitly declare that your logic has successfully rejected a request | ||
* | ||
* Named after HTTPStatusCode_400 | ||
* - > The server cannot or will not process the request due to an apparent caller error | ||
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400 | ||
* | ||
* Commonly used to return an error to the caller while marking the execution as successful | ||
* - e.g., the [simple-lambda-handlers](https://github.com/ehmpathy/simple-lambda-handlers) library returns an error to the caller (to notify them of the rejection) while marking the lambda invocation as successful (to avoid cloudwatch metric errors and automated retries) | ||
*/ | ||
export class BadRequestError extends HelpfulError { | ||
constructor(message: string, metadata?: Record<string, any>) { | ||
super(['BadRequestError: ', message].join(''), metadata); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { HelpfulError } from './HelpfulError'; | ||
|
||
describe('HelpfulError', () => { | ||
it('should produce a helpful, observable error message', () => { | ||
const error = new HelpfulError('the dogs were let out', { | ||
who: 'your mom', | ||
}); | ||
expect(error).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.