Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/nestjs/src/DevCycleModule/DevCycleModuleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DevCycleOptions, DevCycleUser } from '@devcycle/nodejs-server-sdk'
export interface DevCycleModuleOptions {
key: string
options?: Omit<DevCycleOptions, 'enableCloudBucketing'>
userFactory: (context: ExecutionContext) => DevCycleUser
userFactory?: (context: ExecutionContext) => DevCycleUser
}

export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } =
Expand Down
8 changes: 7 additions & 1 deletion sdk/nestjs/src/DevCycleModule/DevCycleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ export class DevCycleService {
) {}

getUser(): DevCycleUser {
return this.cls.get('dvc_user')
const user = this.cls.get('dvc_user')
if (!user) {
throw new Error(
'Missing user context. Is the DevCycleModule imported and a user factory set?',
)
}
return user
}

isEnabled(key: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion sdk/nestjs/src/DevCycleModule/RequestInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class RequestInterceptor implements NestInterceptor {
next: CallHandler,
): ReturnType<CallHandler['handle']> {
this.cls.set('dvc_client', this.client)
this.cls.set('dvc_user', this.options.userFactory(context))
this.cls.set('dvc_user', this.options.userFactory?.(context))

return next.handle()
}
Expand Down
3 changes: 2 additions & 1 deletion sdk/nestjs/src/RequireVariableValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const RequireVariableValueInterceptor = (

if (!user) {
throw new Error(
'Missing user context. Is the DevCycleModule imported?',
'User context is missing. ' +
'Ensure that the DevCycleModule is imported and a user factory is configured.',
)
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/nestjs/src/VariableValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const VariableValue = createParamDecorator((data: VariableValueData) => {

if (!client || !user) {
throw new Error(
'Missing DevCycle context. Is the DevCycleModule imported?',
'DevCycle context is missing. Ensure that the DevCycleModule is imported and a user factory is configured.',
)
}

Expand Down