From cae471105eae00355ff581c3e3ce3510d8198942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Sun, 29 Aug 2021 14:49:32 +0000 Subject: [PATCH] API-15: Error reference codes (#14) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Patrick Müller Reviewed-on: https://git.plutodev.de/PlutoDev/plutoapi-v2/pulls/14 Co-authored-by: Patrick Müller Co-committed-by: Patrick Müller --- src/models/dhbw-service/DHBWService.router.ts | 10 ++++++++-- .../generalInfo/GeneralInfo.router.ts | 19 +++++++++++++++---- src/models/partyplaner/PartyPlaner.router.ts | 10 ++++++++-- src/models/partyplaner/event/Event.router.ts | 11 +++++++++-- .../friendship/Friendship.router.ts | 10 ++++++++-- .../partyplaner/invite/Invite.router.ts | 10 ++++++++-- src/models/partyplaner/login/Login.router.ts | 10 ++++++++-- .../partyplaner/register/Register.router.ts | 10 ++++++++-- .../partyplaner/session/Session.router.ts | 10 ++++++++-- src/models/partyplaner/user/User.router.ts | 10 ++++++++-- .../HighlightMarker.router.ts | 10 ++++++++-- .../addHighlight/AddHighlight.router.ts | 19 +++++++++++++++---- 12 files changed, 111 insertions(+), 28 deletions(-) diff --git a/src/models/dhbw-service/DHBWService.router.ts b/src/models/dhbw-service/DHBWService.router.ts index 6a2e05b..26c6775 100644 --- a/src/models/dhbw-service/DHBWService.router.ts +++ b/src/models/dhbw-service/DHBWService.router.ts @@ -4,6 +4,7 @@ import express, {Request, Response} from 'express'; import {generalInfoRouter} from './generalInfo/GeneralInfo.router'; import logger from '../../middleware/logger'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -17,7 +18,12 @@ dhbwServiceRouter.get('/', async (req: Request, res: Response) => { try { res.status(200).send('Pluto Development DHBW Service App API Endpoint'); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); diff --git a/src/models/dhbw-service/generalInfo/GeneralInfo.router.ts b/src/models/dhbw-service/generalInfo/GeneralInfo.router.ts index 0667943..237c86f 100644 --- a/src/models/dhbw-service/generalInfo/GeneralInfo.router.ts +++ b/src/models/dhbw-service/generalInfo/GeneralInfo.router.ts @@ -3,6 +3,7 @@ */ import express, {Request, Response} from 'express'; import logger from '../../../middleware/logger'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -13,8 +14,13 @@ generalInfoRouter.get('/', async (req: Request, res: Response) => { try { res.status(200).send('GET generalInfo v2.1'); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); @@ -22,7 +28,12 @@ generalInfoRouter.post('/', async (req: Request, res: Response) => { try { res.status(200).send('POST generalInfo v2.1'); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); diff --git a/src/models/partyplaner/PartyPlaner.router.ts b/src/models/partyplaner/PartyPlaner.router.ts index 951bd46..a0b2dbe 100644 --- a/src/models/partyplaner/PartyPlaner.router.ts +++ b/src/models/partyplaner/PartyPlaner.router.ts @@ -10,6 +10,7 @@ import {eventRouter} from './event/Event.router'; import {friendshipRouter} from './friendship/Friendship.router'; import {inviteRouter} from './invite/Invite.router'; import {sessionRouter} from './session/Session.router'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -29,7 +30,12 @@ partyPlanerRouter.get('/', async (req: Request, res: Response) => { try { res.status(200).send('Pluto Development PartyPlaner API Endpoint V2'); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); diff --git a/src/models/partyplaner/event/Event.router.ts b/src/models/partyplaner/event/Event.router.ts index e3dd304..345b3be 100644 --- a/src/models/partyplaner/event/Event.router.ts +++ b/src/models/partyplaner/event/Event.router.ts @@ -5,6 +5,7 @@ import express, {Request, Response} from 'express'; import * as EventService from './event.service'; import * as UserService from '../user/user.service'; import logger from '../../../middleware/logger'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -13,6 +14,7 @@ export const eventRouter = express.Router(); eventRouter.get('/:isDevCall', async (req: Request, res: Response) => { try { + throw new Error('Test'); let userId = (req.query.userId ?? '').toString(); let sessionId = (req.query.sessionId ?? '').toString(); let sessionKey = (req.query.sessionKey ?? '').toString(); @@ -38,7 +40,12 @@ eventRouter.get('/:isDevCall', async (req: Request, res: Response) => { res.status(200).send(data); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); diff --git a/src/models/partyplaner/friendship/Friendship.router.ts b/src/models/partyplaner/friendship/Friendship.router.ts index e172418..7eb6793 100644 --- a/src/models/partyplaner/friendship/Friendship.router.ts +++ b/src/models/partyplaner/friendship/Friendship.router.ts @@ -5,6 +5,7 @@ import express, {Request, Response} from 'express'; import * as FriendshipService from './friendship.service'; import * as UserService from '../user/user.service'; import logger from '../../../middleware/logger'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -38,7 +39,12 @@ friendshipRouter.get('/:isDevCall', async (req: Request, res: Response) => { res.status(200).send(data); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); diff --git a/src/models/partyplaner/invite/Invite.router.ts b/src/models/partyplaner/invite/Invite.router.ts index e006f80..ac98905 100644 --- a/src/models/partyplaner/invite/Invite.router.ts +++ b/src/models/partyplaner/invite/Invite.router.ts @@ -5,6 +5,7 @@ import express, {Request, Response} from 'express'; import * as InviteService from './invite.service'; import * as UserService from '../user/user.service'; import logger from '../../../middleware/logger'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -38,7 +39,12 @@ inviteRouter.get('/:isDevCall', async (req: Request, res: Response) => { res.status(200).send(data); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); diff --git a/src/models/partyplaner/login/Login.router.ts b/src/models/partyplaner/login/Login.router.ts index fec4303..e210d54 100644 --- a/src/models/partyplaner/login/Login.router.ts +++ b/src/models/partyplaner/login/Login.router.ts @@ -4,6 +4,7 @@ import express, {Request, Response} from 'express'; import * as UserService from '../user/user.service'; import logger from '../../../middleware/logger'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -52,7 +53,12 @@ loginRouter.post('/:isDevCall', async (req: Request, res: Response) => { res.status(200).send(session); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); diff --git a/src/models/partyplaner/register/Register.router.ts b/src/models/partyplaner/register/Register.router.ts index 6da865b..34a91e1 100644 --- a/src/models/partyplaner/register/Register.router.ts +++ b/src/models/partyplaner/register/Register.router.ts @@ -4,6 +4,7 @@ import express, {Request, Response} from 'express'; import * as UserService from '../user/user.service'; import logger from '../../../middleware/logger'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -71,7 +72,12 @@ registerRouter.post('/:isDevCall', async (req: Request, res: Response) => { res.status(201).send(session); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); diff --git a/src/models/partyplaner/session/Session.router.ts b/src/models/partyplaner/session/Session.router.ts index 73dd3cb..ccbf16c 100644 --- a/src/models/partyplaner/session/Session.router.ts +++ b/src/models/partyplaner/session/Session.router.ts @@ -5,6 +5,7 @@ import express, {Request, Response} from 'express'; import * as SessionService from './session.service'; import * as UserService from '../user/user.service'; import logger from '../../../middleware/logger'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -38,7 +39,12 @@ sessionRouter.get('/:isDevCall', async (req: Request, res: Response) => { res.status(200).send(data); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); diff --git a/src/models/partyplaner/user/User.router.ts b/src/models/partyplaner/user/User.router.ts index c7173e0..e1ffc8f 100644 --- a/src/models/partyplaner/user/User.router.ts +++ b/src/models/partyplaner/user/User.router.ts @@ -4,6 +4,7 @@ import express, {Request, Response} from 'express'; import * as UserService from './user.service'; import logger from '../../../middleware/logger'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -37,7 +38,12 @@ userRouter.get('/:isDevCall', async (req: Request, res: Response) => { res.status(200).send(data); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); diff --git a/src/models/twitch-highlight-marker/HighlightMarker.router.ts b/src/models/twitch-highlight-marker/HighlightMarker.router.ts index 8dabce3..7ad3976 100644 --- a/src/models/twitch-highlight-marker/HighlightMarker.router.ts +++ b/src/models/twitch-highlight-marker/HighlightMarker.router.ts @@ -4,6 +4,7 @@ import express, {Request, Response} from 'express'; import {addHighlightRouter} from './addHighlight/AddHighlight.router'; import logger from '../../middleware/logger'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -16,7 +17,12 @@ highlightMarkerRouter.get('/', async (req: Request, res: Response) => { try { res.status(200).send('Pluto Development Twitch Highlight Marker API Endpoint'); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); diff --git a/src/models/twitch-highlight-marker/addHighlight/AddHighlight.router.ts b/src/models/twitch-highlight-marker/addHighlight/AddHighlight.router.ts index 3637ac0..31f72bd 100644 --- a/src/models/twitch-highlight-marker/addHighlight/AddHighlight.router.ts +++ b/src/models/twitch-highlight-marker/addHighlight/AddHighlight.router.ts @@ -4,6 +4,7 @@ import express, {Request, Response} from 'express'; import * as AddHighlightService from './addHighlights.service'; import logger from '../../../middleware/logger'; +import {Guid} from 'guid-typescript'; /** * Router Definition @@ -14,8 +15,13 @@ addHighlightRouter.get('/', (req: Request, res: Response) => { try { res.status(200).send('GET endpoint not defined.'); } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } }); @@ -40,7 +46,12 @@ addHighlightRouter.post('/', (req: Request, res: Response) => { res.status(200).send({'status': 'success', 'description': ''}); } } catch (e) { - logger.error('Error handling a request: ' + e.message); - res.status(500).send({'message': 'Internal Server Error. Try again later.'}); + let errorGuid = Guid.create().toString(); + logger.error('Error handling a request: ' + e.message, {reference: errorGuid}); + res.status(500).send({ + 'status': 'PROCESSING_ERROR', + 'message': 'Internal Server Error. Try again later.', + 'reference': errorGuid + }); } });