Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added adapter custom err type (#282) #73

Merged
merged 1 commit into from
Jul 30, 2023
Merged

Conversation

4lessandrodev
Copy link
Owner

4lessandrodev/type-ddd#282

Example implementation

	type In = { a: number };
	type Out = { b: string };
	type Err = { err: string; stack?: string };

	class CustomAdapter implements IAdapter<In, Out, Err>{
		build(target: In): IResult<Out, Err> {
			if (typeof target.a !== 'number') return Fail({ err: 'target.a is not a number' });
			return Ok({ b: target.a.toString() });
		}
	}

	const adapter = new CustomAdapter();

Example payload

	const result = adapter.build({ a: null as any });
	expect(result.isFail()).toBeTruthy();
	expect(result.error()).toEqual({ err: 'target.a is not a number' });

@4lessandrodev 4lessandrodev merged commit 65a4a4f into main Jul 30, 2023
1 check passed
@4lessandrodev 4lessandrodev deleted the fix/adapter branch July 30, 2023 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant