Skip to content

Commit

Permalink
feat: env logger
Browse files Browse the repository at this point in the history
  • Loading branch information
denchiklut committed Sep 29, 2024
1 parent 6d0d74e commit 52ccd16
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/common/env/env.util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ObjectSchema, InferType, AnyObject } from 'yup'
import { parse } from './parse.util'
import { logger } from '../logger'

interface Props<T extends AnyObject> {
schema: ObjectSchema<T>
Expand All @@ -12,10 +13,10 @@ export function createEnv<S extends AnyObject>({
clientPrefix = 'CLIENT_'
}: Props<S>) {
const client = schema.pick(Object.keys(schema.shape).filter(k => k.startsWith(clientPrefix)))
const { data, error } = parse((IS_SERVER || IS_SPA ? schema : client) as ObjectSchema<S>, envs)
const { data, error } = parse((IS_SERVER ? schema : client) as ObjectSchema<S>, envs)

if (error) {
console.error('❌ Invalid environment variables:', error.errors)
logger.error('❌ Invalid environment variables:', error.errors)
throw new Error('Invalid environment variables')
}

Expand Down

0 comments on commit 52ccd16

Please sign in to comment.