diff --git a/api/controllers/v1/github.ts b/api/controllers/v1/github.ts index 942d930c5..c087aadcd 100644 --- a/api/controllers/v1/github.ts +++ b/api/controllers/v1/github.ts @@ -6,6 +6,7 @@ import { RepoBranchesRepository } from '../../../src/repositories/repoBranchesRe import { markBuildArtifactsForDeletion, validateJsonWebhook } from '../../handlers/github'; import { DocsetsRepository } from '../../../src/repositories/docsetsRepository'; import { ReposBranchesDocsetsDocument } from '../../../modules/persistence/src/services/metadata/repos_branches'; +import { PushEvent } from '@octokit/webhooks-types'; async function prepGithubPushPayload( githubEvent: any, @@ -87,9 +88,17 @@ export const TriggerBuild = async (event: any = {}, context: any = {}): Promise< }; } - throw new Error(`event body? => ${JSON.stringify(event.body)}`); - - const body = JSON.parse(event.body); + let body: PushEvent; + try { + body = JSON.parse(event.body) as PushEvent; + } catch (e) { + console.log('[TriggerBuild]: ERROR! Could not parse event.body', e); + return { + statusCode: 502, + headers: { 'Content-Type': 'text/plain' }, + body: ' ERROR! Could not parse event.body', + }; + } if (body.deleted) { return { diff --git a/src/services/repo.ts b/src/services/repo.ts index b5e780b1b..77f177a03 100644 --- a/src/services/repo.ts +++ b/src/services/repo.ts @@ -5,7 +5,6 @@ import { IConfig } from 'config'; import { InvalidJobError } from '../errors/errors'; import { IFileSystemServices } from './fileServices'; import simpleGit, { SimpleGit } from 'simple-git'; -import { getDirectory } from '../job/jobHandler'; const git: SimpleGit = simpleGit(); export interface IRepoConnector {