-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/common-graphql-error-handler
- Loading branch information
Showing
8 changed files
with
123 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { HttpService } from '@nestjs/axios'; | ||
import TransportStream = require('winston-transport'); | ||
import { TransportStreamOptions } from 'winston-transport'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { Logger } from '@nestjs/common/services/logger.service'; | ||
import { firstValueFrom } from 'rxjs'; | ||
|
||
interface CustomTransportOptions extends TransportStreamOptions { | ||
httpService: HttpService; | ||
configService: ConfigService; | ||
} | ||
|
||
interface LogInfo { | ||
level: string; | ||
message: string; | ||
timestamp?: string; | ||
context?: string; | ||
stack?: string; | ||
severity: string; | ||
} | ||
|
||
export class SlogerrTransport extends TransportStream { | ||
private readonly httpService: HttpService; | ||
private readonly configService: ConfigService; | ||
private readonly logger = new Logger(SlogerrTransport.name); | ||
|
||
constructor(options: CustomTransportOptions) { | ||
super(options); | ||
this.httpService = options.httpService; | ||
this.configService = options.configService; | ||
} | ||
|
||
async log(info: LogInfo, callback: () => void): Promise<void> { | ||
const allowedLevels = (this.configService.get<string>('SLOGGER_LOG_LEVEL') || 'error') | ||
.split(',') | ||
.map((level) => level.trim()); | ||
const logType = this.configService.get<string>('SLOGGER_LOG_TYPE') || 'Exceptions'; | ||
|
||
if (allowedLevels.includes(info.level)) { | ||
const apiEndpoint = this.configService.get<string>('SLOGERR_API_ENDPOINT'); | ||
const apiKey = this.configService.get<string>('SLOGERR_API_TOKEN'); | ||
|
||
this.logger.log(`Log Info: ${JSON.stringify(info)}`); | ||
|
||
const logCreatedOn = info.timestamp || new Date().toISOString(); | ||
|
||
try { | ||
const response = await firstValueFrom( | ||
this.httpService.post( | ||
apiEndpoint, | ||
{ | ||
moduleName: info.context || 'Unknown Module', | ||
logDescription: info.message, | ||
logType: logType, | ||
logCreatedOn: logCreatedOn, | ||
severity: info.severity, | ||
logData: { | ||
message: info.message, | ||
stack: info.stack, | ||
context: info.context, | ||
}, | ||
}, | ||
{ headers: { 'slogerr-secure-api-key': apiKey } }, | ||
), | ||
); | ||
|
||
if (response.status !== 200) { | ||
this.logger.error( | ||
`Failed to send log to Slogerr. Status: ${response.status}, Message: ${response.statusText}`, | ||
); | ||
} else { | ||
this.logger.log('Error log successfully sent to Slogerr', response); | ||
} | ||
} catch (error) { | ||
this.logger.error('Failed to send log to Slogerr', error.message); | ||
} | ||
} | ||
|
||
callback(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 18 additions & 3 deletions
21
apps/api/src/modules/archived-notifications/archived-notifications.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
import { Controller, Post } from '@nestjs/common'; | ||
import { Controller, HttpException, Logger, Post } from '@nestjs/common'; | ||
import { ArchivedNotificationsService } from './archived-notifications.service'; | ||
|
||
@Controller('archived-notifications') | ||
export class ArchivedNotificationsController { | ||
constructor(private readonly archivedNotificationService: ArchivedNotificationsService) {} | ||
constructor( | ||
private readonly archivedNotificationService: ArchivedNotificationsService, | ||
private logger: Logger = new Logger(ArchivedNotificationsController.name), | ||
) {} | ||
|
||
@Post('archive') | ||
async addNotificationsToQueue(): Promise<void> { | ||
this.archivedNotificationService.archiveCompletedNotificationsCron(); | ||
try { | ||
this.logger.debug('Archiving completed notifications...'); | ||
await this.archivedNotificationService.archiveCompletedNotificationsCron(); | ||
this.logger.log('Notifications archived successfully.'); | ||
} catch (error) { | ||
if (error instanceof HttpException) { | ||
throw error; | ||
} | ||
|
||
this.logger.error('Error while archiving notifications'); | ||
this.logger.error(JSON.stringify(error, ['message', 'stack'], 2)); | ||
throw error; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "osmox-portal", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"scripts": { | ||
"ng": "ng", | ||
"start": "ng serve", | ||
|