Skip to content

Commit

Permalink
fix: ignore drive not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
acaldas committed Jun 19, 2024
1 parent 29a929d commit b7dcf31
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@ import type { Express } from 'express';
import express from 'express';
import { getChildLogger } from './logger';
import basePrisma from './database';
import {
renderPlaygroundPage,
} from 'graphql-playground-html'
import * as Sentry from "@sentry/node";
import { nodeProfilingIntegration } from "@sentry/profiling-node";
import { renderPlaygroundPage } from 'graphql-playground-html';
import * as Sentry from '@sentry/node';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import bodyParser from 'body-parser';
import prisma from './database';

import { dependencies } from "../package.json"

import { dependencies } from '../package.json';

const logger = getChildLogger({ msgPrefix: 'APP' });
const startupTime = new Date();

export const createApp = (): { app: Express, router: express.Router } => {
export const createApp = (): { app: Express; router: express.Router } => {
logger.debug('Creating app');
const app = express();
const router = express.Router();

// fixes request entity too large
app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true, parameterLimit: 50000 }));
app.use(bodyParser.json({ limit: '50mb' }));
app.use(
bodyParser.urlencoded({
limit: '50mb',
extended: true,
parameterLimit: 50000,
})
);

if (process.env.SENTRY_DSN) {
Sentry.init({
Expand All @@ -41,7 +44,7 @@ export const createApp = (): { app: Express, router: express.Router } => {
/^Failed to fetch strands$/,
/Drive with id .+ not found/,
/Document with id .+ not found/,
/Drive not found/,
'Drive not found',
],
});

Expand All @@ -67,41 +70,53 @@ export const createApp = (): { app: Express, router: express.Router } => {
});

app.get('/versions', async (req, res) => {
const { "document-drive": docDrive, "document-model": docModel, "document-model-libs": docModelLibs } = dependencies
res.send({ "document-drive": docDrive, "document-model": docModel, "document-model-libs": docModelLibs })
})

router.get(
'/explorer/:driveId?',
(req, res) => {
res.setHeader('Content-Type', 'text/html')
const basePath = process.env.BASE_PATH === "/" ? "" : process.env.BASE_PATH || '';
const endpoint = `${basePath}${req.params.driveId !== undefined ? `/d/${req.params.driveId}` : '/drives'}`
res.send(renderPlaygroundPage({
const {
'document-drive': docDrive,
'document-model': docModel,
'document-model-libs': docModelLibs,
} = dependencies;
res.send({
'document-drive': docDrive,
'document-model': docModel,
'document-model-libs': docModelLibs,
});
});

router.get('/explorer/:driveId?', (req, res) => {
res.setHeader('Content-Type', 'text/html');
const basePath =
process.env.BASE_PATH === '/' ? '' : process.env.BASE_PATH || '';
const endpoint = `${basePath}${
req.params.driveId !== undefined ? `/d/${req.params.driveId}` : '/drives'
}`;
res.send(
renderPlaygroundPage({
endpoint: endpoint,
settings: {
'request.credentials': 'include',
},
}))
}
);
})
);
});

// Hooks
router.post('/h/github', async (req, res) => {
const issueId = req.body?.issue?.number;
const action = req.body?.action;

if (action !== "closed") {
if (action !== 'closed') {
return res.sendStatus(200);
}

if (!issueId) {
throw new Error('Issue number not found in request body')
throw new Error('Issue number not found in request body');
}

const result = await prisma.document.closeScopeOfWorkIssue(req.body.issue.number)
const result = await prisma.document.closeScopeOfWorkIssue(
req.body.issue.number
);
if (!result) {
throw new Error('Failed to close issue')
throw new Error('Failed to close issue');
}

return res.sendStatus(200).send(result);
Expand Down

0 comments on commit b7dcf31

Please sign in to comment.