-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: the TxSubmit endpoint no longer adds the stack trace when …
…returning domain errors BREAKING CHANGE: - stack property of returned errors was removed
- Loading branch information
1 parent
48eba64
commit f018f30
Showing
5 changed files
with
131 additions
and
1 deletion.
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
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,22 @@ | ||
/** | ||
* Node.js environment configurations. | ||
*/ | ||
export enum Environment { | ||
/** | ||
* Production environment. | ||
* | ||
* Node.js assumes it's always running in a development environment. You can signal Node.js that you are running | ||
* in production by setting the NODE_ENV=production environment variable. | ||
*/ | ||
Production = 'production', | ||
|
||
/** | ||
* Development environment. | ||
*/ | ||
Development = 'development' | ||
} | ||
|
||
export const isProductionEnvironment = (): boolean => process.env.NODE_ENV === Environment.Production; | ||
|
||
export const getEnvironmentConfiguration = (): Environment => | ||
isProductionEnvironment() ? Environment.Production : Environment.Development; |
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
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,68 @@ | ||
import { ComposableError } from '../'; | ||
import { stripStackTrace } from '../src'; | ||
|
||
class TestError<InnerError = unknown> extends ComposableError<InnerError> { | ||
constructor(innerError: InnerError) { | ||
super('Test error', innerError); | ||
} | ||
} | ||
|
||
const throwsError = () => { | ||
throw new Error('a'); | ||
}; | ||
|
||
const throwsComposableError = () => { | ||
try { | ||
throwsError(); | ||
} catch (error) { | ||
throw new TestError(error); | ||
} | ||
}; | ||
|
||
describe('stripStackTrace', () => { | ||
it('doesnt throw if given undefined', () => { | ||
const error = undefined; | ||
expect(() => stripStackTrace(error)).not.toThrow(); | ||
}); | ||
|
||
it('doesnt throw if given null', () => { | ||
const error = null; | ||
expect(() => stripStackTrace(error)).not.toThrow(); | ||
}); | ||
|
||
it('doesnt throw if a non Error object', () => { | ||
const error = { a: 'a' }; | ||
expect(() => stripStackTrace(error)).not.toThrow(); | ||
expect(() => stripStackTrace(10)).not.toThrow(); | ||
expect(() => stripStackTrace('some error')).not.toThrow(); | ||
}); | ||
|
||
it('removes the stack field from the Error object', () => { | ||
try { | ||
throwsError(); | ||
} catch (error) { | ||
stripStackTrace(error); | ||
expect((error as Error).stack).toBeUndefined(); | ||
} | ||
}); | ||
|
||
it('removes the stack field from the Error object and inner errors', () => { | ||
try { | ||
throwsComposableError(); | ||
} catch (error) { | ||
let testError = error as TestError; | ||
let innerError = testError.innerError as Error; | ||
|
||
expect(testError.stack).toBeDefined(); | ||
expect(innerError.stack).toBeDefined(); | ||
|
||
stripStackTrace(error); | ||
|
||
testError = error as TestError; | ||
innerError = testError.innerError as Error; | ||
|
||
expect(testError.stack).toBeUndefined(); | ||
expect(innerError.stack).toBeUndefined(); | ||
} | ||
}); | ||
}); |