This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
-
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(http-driver): throw
LumberjackHttpDriverError
when max HTTP re…
…tries are reached (#21) Co-authored-by: Nacho Vazquez <[email protected]>
- Loading branch information
1 parent
f2521ad
commit c0e3e64
Showing
21 changed files
with
1,535 additions
and
1,308 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
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
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
10 changes: 10 additions & 0 deletions
10
libs/ngworker/lumberjack/http-driver/src/errors-api.spec.ts
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 { isClass } from '@internal/test-util'; | ||
import { LumberjackHttpDriverError } from './index'; | ||
|
||
describe('Errors API', () => { | ||
it(`exposes ${LumberjackHttpDriverError.name}`, () => { | ||
const sut = LumberjackHttpDriverError; | ||
|
||
expect(isClass(sut)).toBeTruthy(); | ||
}); | ||
}); |
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
28 changes: 28 additions & 0 deletions
28
libs/ngworker/lumberjack/http-driver/src/lib/errors/lumberjack-http-driver.error.spec.ts
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,28 @@ | ||
import { LumberjackHttpDriverError } from './lumberjack-http-driver.error'; | ||
|
||
describe(LumberjackHttpDriverError.name, () => { | ||
it('has the default error message "LumberjackHttpDriverError"', () => { | ||
const error = new LumberjackHttpDriverError(); | ||
|
||
expect(error.message).toBe('LumberjackHttpDriverError'); | ||
}); | ||
|
||
it('accepts a custom error message', () => { | ||
const expectedMessage = 'The water stream has dried up'; | ||
const error = new LumberjackHttpDriverError(expectedMessage); | ||
|
||
expect(error.message).toBe(expectedMessage); | ||
}); | ||
|
||
it('is an instance of Error', () => { | ||
const error = new LumberjackHttpDriverError(); | ||
|
||
expect(error).toBeInstanceOf(Error); | ||
}); | ||
|
||
it('has the error name ""LumberjackHttpDriverError"', () => { | ||
const error = new LumberjackHttpDriverError(); | ||
|
||
expect(error.name).toBe('LumberjackHttpDriverError'); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
libs/ngworker/lumberjack/http-driver/src/lib/errors/lumberjack-http-driver.error.ts
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,13 @@ | ||
export class LumberjackHttpDriverError extends Error { | ||
constructor(message: string = 'LumberjackHttpDriverError') { | ||
super(message); | ||
this.name = 'LumberjackHttpDriverError'; | ||
|
||
// Non-standard V8 function for maintaining a stack trace | ||
const ErrorWithCaptureStackTrace = Error as unknown as Error & { | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
captureStackTrace?: (targetObject: object, constructorOpt?: Function) => void; | ||
}; | ||
ErrorWithCaptureStackTrace.captureStackTrace?.(this, this.constructor); | ||
} | ||
} |
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
9 changes: 6 additions & 3 deletions
9
libs/ngworker/lumberjack/http-driver/src/lib/operators/retry-with-delay.operator.ts
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,7 +1,10 @@ | ||
import { concat, MonoTypeOperatorFunction, throwError } from 'rxjs'; | ||
import { delay, retryWhen, take } from 'rxjs/operators'; | ||
import { concat, delay, MonoTypeOperatorFunction, retryWhen, take, throwError } from 'rxjs'; | ||
import { LumberjackHttpDriverError } from '../errors/lumberjack-http-driver.error'; | ||
|
||
export const retryWithDelay = <T>(maxRetries: number, delayMs: number): MonoTypeOperatorFunction<T> => | ||
retryWhen<T>((errors) => | ||
concat(errors.pipe(delay(delayMs), take(maxRetries + 1)), throwError(`Failed after ${maxRetries} retries.`)) | ||
concat( | ||
errors.pipe(delay(delayMs), take(maxRetries + 1)), | ||
throwError(() => new LumberjackHttpDriverError(`Failed after ${maxRetries} retries.`)) | ||
) | ||
); |
18 changes: 18 additions & 0 deletions
18
libs/ngworker/lumberjack/src/lib/errors/lumberjack-http-driver.error.ts
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,18 @@ | ||
export class LumberjackHttpDriverError extends Error { | ||
constructor(message: string = 'LumberjackHttpDriverError') { | ||
super(message); | ||
|
||
// LumberjackHttpDriverError instanceof Error === true | ||
Object.setPrototypeOf(this, new.target.prototype); | ||
|
||
// Error name | ||
this.name = 'LumberjackHttpDriverError'; | ||
|
||
// Non-standard V8 function for maintaining a stack trace | ||
const ErrorWithCaptureStackTrace = Error as unknown as Error & { | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
captureStackTrace?: (error: Error, constructor: Function) => void; | ||
}; | ||
ErrorWithCaptureStackTrace.captureStackTrace?.(this, this.constructor); | ||
} | ||
} |
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
Oops, something went wrong.