Skip to content

Commit

Permalink
feat(Context): Add lastError field to request context
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen-plug committed Sep 15, 2021
1 parent 570de49 commit c28bf93
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/easy-express/src/types/NamespaceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export class NamespaceContext implements RequestContext {
this.namespace.set('correlationId', id);
}

get lastError(): string | undefined {
return this.namespace.get('lastError');
}

set lastError(error: string | undefined) {
this.namespace.set('lastError', error);
}

public get(key: string): any {
return this.namespace.get(key);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/easy-express/test/types/NamespaceContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ describe('NamespaceContext', () => {
context.create(() => {
context.token = 'token';
context.correlationId = 'correlation';
context.lastError = 'error';
expect(context.token).toBe('token');
expect(context.correlationId).toBe('correlation');
expect(context.lastError).toBe('error');
});
});
});
9 changes: 9 additions & 0 deletions packages/easy/src/types/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type RequestContext = {
identity?: Identity;
jwt: string;
correlationId?: Uuid;
lastError?: string;
create: (f: () => void) => void;
};

Expand Down Expand Up @@ -64,6 +65,14 @@ export class BaseContext implements RequestContext {
this.state.correlationId = id;
}

get lastError(): string | undefined {
return this.state.lastError;
}

set lastError(error: string | undefined) {
this.state.lastError = error;
}

public get(key: string): any {
return this.state[key];
}
Expand Down

0 comments on commit c28bf93

Please sign in to comment.