Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #651 from input-output-hk/feat/adp-1552-strip-stac…
…k-trace-from-tx-submit refactor!: the TxSubmit endpoint no longer adds the stack trace when …
- Loading branch information
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(); | ||
} | ||
}); | ||
}); |