diff --git a/packages/hoppscotch-backend/src/infra-config/helper.ts b/packages/hoppscotch-backend/src/infra-config/helper.ts index 2ca6cadfe..66ff9910e 100644 --- a/packages/hoppscotch-backend/src/infra-config/helper.ts +++ b/packages/hoppscotch-backend/src/infra-config/helper.ts @@ -12,16 +12,22 @@ export enum AuthProviderStatus { * (ConfigModule will set the environment variables in the process) */ export async function loadInfraConfiguration() { - const prisma = new PrismaService(); + try { + const prisma = new PrismaService(); - const infraConfigs = await prisma.infraConfig.findMany(); + const infraConfigs = await prisma.infraConfig.findMany(); - let environmentObject: Record = {}; - infraConfigs.forEach((infraConfig) => { - environmentObject[infraConfig.name] = infraConfig.value; - }); + let environmentObject: Record = {}; + infraConfigs.forEach((infraConfig) => { + environmentObject[infraConfig.name] = infraConfig.value; + }); - return { INFRA: environmentObject }; + return { INFRA: environmentObject }; + } catch (error) { + // Prisma throw error if 'Can't reach at database server' OR 'Table does not exist' + // We're not throwing error here because we want to allow the app to run 'pnpm install' + return { INFRA: {} }; + } } /** diff --git a/packages/hoppscotch-backend/src/infra-config/infra-config.service.spec.ts b/packages/hoppscotch-backend/src/infra-config/infra-config.service.spec.ts index 3c5507902..7c236dd55 100644 --- a/packages/hoppscotch-backend/src/infra-config/infra-config.service.spec.ts +++ b/packages/hoppscotch-backend/src/infra-config/infra-config.service.spec.ts @@ -1,7 +1,10 @@ import { mockDeep, mockReset } from 'jest-mock-extended'; import { PrismaService } from 'src/prisma/prisma.service'; import { InfraConfigService } from './infra-config.service'; -import { InfraConfigEnum } from 'src/types/InfraConfig'; +import { + InfraConfigEnum, + InfraConfigEnumForClient, +} from 'src/types/InfraConfig'; import { INFRA_CONFIG_NOT_FOUND, INFRA_CONFIG_UPDATE_FAILED } from 'src/errors'; import { ConfigService } from '@nestjs/config'; import * as helper from './helper'; @@ -68,7 +71,7 @@ describe('InfraConfigService', () => { describe('get', () => { it('should get the infra config', async () => { - const name = InfraConfigEnum.GOOGLE_CLIENT_ID; + const name = InfraConfigEnumForClient.GOOGLE_CLIENT_ID; const value = 'true'; mockPrisma.infraConfig.findUniqueOrThrow.mockResolvedValueOnce({ @@ -84,7 +87,7 @@ describe('InfraConfigService', () => { }); it('should pass correct params to prisma findUnique', async () => { - const name = InfraConfigEnum.GOOGLE_CLIENT_ID; + const name = InfraConfigEnumForClient.GOOGLE_CLIENT_ID; await infraConfigService.get(name); @@ -95,7 +98,7 @@ describe('InfraConfigService', () => { }); it('should throw an error if the infra config does not exist', async () => { - const name = InfraConfigEnum.GOOGLE_CLIENT_ID; + const name = InfraConfigEnumForClient.GOOGLE_CLIENT_ID; mockPrisma.infraConfig.findUniqueOrThrow.mockRejectedValueOnce('null'); diff --git a/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts b/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts index f32b20465..a47d34b48 100644 --- a/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts +++ b/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts @@ -105,7 +105,10 @@ export class InfraConfigService implements OnModuleInit { stopApp(); } } catch (error) { - if (error.code === 'P2021') { + if (error.code === 'P1001') { + // Prisma error code for 'Can't reach at database server' + // We're not throwing error here because we want to allow the app to run 'pnpm install' + } else if (error.code === 'P2021') { // Prisma error code for 'Table does not exist' throwErr(DATABASE_TABLE_NOT_EXIST); } else {