Skip to content

Commit b566fae

Browse files
authored
Release 2025-08-25 (#3510)
2 parents 02ef534 + ef2e509 commit b566fae

75 files changed

Lines changed: 1048 additions & 559 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/apps/dashboard/server/.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ S3_SECRET_KEY=human-oracle-s3-secret
2121
S3_BUCKET=dashboard-hcaptcha-historical-stats
2222
S3_USE_SSL=false
2323

24-
#Web3
24+
# Web3
2525
WEB3_ENV=testnet
2626
RPC_URL_POLYGON=https://rpc-amoy.polygon.technology
2727
RPC_URL_BSC_TESTNET=https://bsc-testnet.drpc.org
2828
RPC_URL_SEPOLIA=https://rpc.sepolia.org
2929

3030
# Reputation Oracle URL
3131
REPUTATION_SOURCE_URL=http://0.0.0.0:5001
32+
33+
# hCaptcha stats
34+
HCAPTCHA_STATS_ENABLED=false

packages/apps/dashboard/server/src/app.module.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
import { CacheModule } from '@nestjs/cache-manager';
22
import { Module } from '@nestjs/common';
33
import { ConfigModule } from '@nestjs/config';
4+
import { APP_FILTER } from '@nestjs/core';
45
import { ScheduleModule } from '@nestjs/schedule';
56

67
import * as Joi from 'joi';
78

89
import { AppController } from './app.controller';
910
import { CacheFactoryConfig } from './common/config/cache-factory.config';
1011
import { CommonConfigModule } from './common/config/config.module';
12+
import { ExceptionFilter } from './common/filters/exception.filter';
1113
import Environment from './common/utils/environment';
1214
import { DetailsModule } from './modules/details/details.module';
1315
import { NetworksModule } from './modules/networks/networks.module';
1416
import { StatsModule } from './modules/stats/stats.module';
1517

1618
@Module({
19+
providers: [
20+
{
21+
provide: APP_FILTER,
22+
useClass: ExceptionFilter,
23+
},
24+
],
1725
imports: [
1826
ConfigModule.forRoot({
1927
/**
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import {
2+
ArgumentsHost,
3+
Catch,
4+
ExceptionFilter as IExceptionFilter,
5+
HttpStatus,
6+
HttpException,
7+
} from '@nestjs/common';
8+
import { Request, Response } from 'express';
9+
10+
import logger from '../../logger';
11+
12+
@Catch()
13+
export class ExceptionFilter implements IExceptionFilter {
14+
private readonly logger = logger.child({ context: ExceptionFilter.name });
15+
16+
catch(exception: unknown, host: ArgumentsHost) {
17+
const ctx = host.switchToHttp();
18+
const response = ctx.getResponse<Response>();
19+
const request = ctx.getRequest<Request>();
20+
21+
let status = HttpStatus.INTERNAL_SERVER_ERROR;
22+
const responseBody: { message: string; [x: string]: unknown } = {
23+
message: 'Internal server error',
24+
};
25+
26+
if (exception instanceof HttpException) {
27+
status = exception.getStatus();
28+
const exceptionResponse = exception.getResponse();
29+
if (typeof exceptionResponse === 'string') {
30+
responseBody.message = exceptionResponse;
31+
} else {
32+
Object.assign(
33+
responseBody,
34+
{
35+
message: exception.message,
36+
},
37+
exceptionResponse,
38+
);
39+
}
40+
} else {
41+
this.logger.error('Unhandled exception', {
42+
error: exception,
43+
path: request.url,
44+
});
45+
}
46+
47+
response.removeHeader('Cache-Control');
48+
49+
response.status(status).json(
50+
Object.assign(
51+
{
52+
statusCode: status,
53+
path: request.url,
54+
timestamp: new Date().toISOString(),
55+
},
56+
responseBody,
57+
),
58+
);
59+
}
60+
}

packages/apps/dashboard/server/src/common/utils/environment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Environment {
1010
static readonly name: string =
1111
process.env.NODE_ENV || EnvironmentName.DEVELOPMENT;
1212

13+
static readonly version: string = process.env.GIT_HASH || 'n/a';
14+
1315
static isDevelopment(): boolean {
1416
return [
1517
EnvironmentName.DEVELOPMENT,

packages/apps/dashboard/server/src/logger/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1-
import { createLogger, NestLogger, LogLevel } from '@human-protocol/logger';
1+
import {
2+
createLogger,
3+
NestLogger,
4+
LogLevel,
5+
isLogLevel,
6+
} from '@human-protocol/logger';
27

38
import Environment from '../common/utils/environment';
49

510
const isDevelopment = Environment.isDevelopment();
611

12+
const LOG_LEVEL_OVERRIDE = process.env.LOG_LEVEL;
13+
14+
let logLevel = LogLevel.INFO;
15+
if (isLogLevel(LOG_LEVEL_OVERRIDE)) {
16+
logLevel = LOG_LEVEL_OVERRIDE;
17+
} else if (isDevelopment) {
18+
logLevel = LogLevel.DEBUG;
19+
}
20+
721
const defaultLogger = createLogger(
822
{
923
name: 'DefaultLogger',
10-
level: isDevelopment ? LogLevel.DEBUG : LogLevel.INFO,
24+
level: logLevel,
1125
pretty: isDevelopment,
1226
disabled: Environment.isTest(),
1327
},
1428
{
1529
environment: Environment.name,
1630
service: 'human-protocol-dashboard',
31+
version: Environment.version,
1732
},
1833
);
1934

packages/apps/dashboard/server/src/modules/stats/stats.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class StatsService implements OnModuleInit {
8585
private async fetchHistoricalHcaptchaStats(): Promise<void> {
8686
let startDate = dayjs(HCAPTCHA_STATS_API_START_DATE);
8787

88-
this.logger.info('Fetching historical hCaptcha stats', {
88+
this.logger.debug('Fetching historical hCaptcha stats', {
8989
startDate,
9090
});
9191

@@ -169,7 +169,7 @@ export class StatsService implements OnModuleInit {
169169
const from = today;
170170
const to = today;
171171

172-
this.logger.info('Fetching hCaptcha stats for today', { from, to });
172+
this.logger.debug('Fetching hCaptcha stats for today', { from, to });
173173

174174
try {
175175
const { data } = await lastValueFrom(
@@ -235,7 +235,7 @@ export class StatsService implements OnModuleInit {
235235

236236
@Cron('*/15 * * * *')
237237
async fetchHmtGeneralStats() {
238-
this.logger.info('Fetching HMT general stats across multiple networks');
238+
this.logger.debug('Fetching HMT general stats across multiple networks');
239239

240240
try {
241241
const aggregatedStats: HmtGeneralStatsDto = {

packages/apps/fortune/exchange-oracle/server/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
"start:prod": "node dist/src/main",
1616
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
1717
"test": "jest",
18-
"migration:create": "yarn build && typeorm-ts-node-commonjs migration:create",
19-
"migration:generate": "yarn build && typeorm-ts-node-commonjs migration:generate -p -d typeorm.config.ts",
20-
"migration:revert": "yarn build && typeorm-ts-node-commonjs migration:revert -d typeorm.config.ts",
21-
"migration:run": "yarn build && typeorm-ts-node-commonjs migration:run -d typeorm.config.ts",
22-
"migration:show": "yarn build && typeorm-ts-node-commonjs migration:show -d typeorm.config.ts",
18+
"migration:create": "yarn typeorm migration:create",
19+
"migration:generate": "yarn typeorm migration:generate -p -d typeorm.config.ts",
20+
"migration:revert": "yarn typeorm migration:revert -d typeorm.config.ts",
21+
"migration:run": "yarn typeorm migration:run -d typeorm.config.ts",
22+
"migration:show": "yarn typeorm migration:show -d typeorm.config.ts",
2323
"test:watch": "jest --watch",
2424
"test:cov": "jest --coverage",
2525
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
2626
"setup:local": "ts-node ./scripts/setup-staking.ts && LOCAL=true yarn setup:kvstore",
2727
"setup:kvstore": "ts-node ./scripts/setup-kv-store.ts",
28-
"generate-env-doc": "ts-node scripts/generate-env-doc.ts"
28+
"generate-env-doc": "ts-node scripts/generate-env-doc.ts",
29+
"typeorm": "typeorm-ts-node-commonjs"
2930
},
3031
"dependencies": {
3132
"@human-protocol/logger": "workspace:*",

packages/apps/fortune/exchange-oracle/server/src/common/exceptions/exception.filter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export class ExceptionFilter implements IExceptionFilter {
5252
const message = exception.message || 'Internal server error';
5353

5454
if (status === HttpStatus.INTERNAL_SERVER_ERROR) {
55-
this.logger.error('Unhandled exception', exception);
55+
this.logger.error('Unhandled exception', {
56+
error: exception,
57+
path: request.url,
58+
});
5659
}
5760

5861
response.removeHeader('Cache-Control');

packages/apps/fortune/exchange-oracle/server/src/common/utils/environment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class Environment {
99
static readonly name: string =
1010
process.env.NODE_ENV || EnvironmentName.DEVELOPMENT;
1111

12+
static readonly version: string = process.env.GIT_HASH || 'n/a';
13+
1214
static isDevelopment(): boolean {
1315
return [
1416
EnvironmentName.DEVELOPMENT,

packages/apps/fortune/exchange-oracle/server/src/logger/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1-
import { createLogger, NestLogger, LogLevel } from '@human-protocol/logger';
1+
import {
2+
createLogger,
3+
NestLogger,
4+
LogLevel,
5+
isLogLevel,
6+
} from '@human-protocol/logger';
27

38
import Environment from '../common/utils/environment';
49

510
const isDevelopment = Environment.isDevelopment();
11+
const LOG_LEVEL_OVERRIDE = process.env.LOG_LEVEL;
12+
13+
let logLevel = LogLevel.INFO;
14+
if (isLogLevel(LOG_LEVEL_OVERRIDE)) {
15+
logLevel = LOG_LEVEL_OVERRIDE;
16+
} else if (isDevelopment) {
17+
logLevel = LogLevel.DEBUG;
18+
}
619

720
const defaultLogger = createLogger(
821
{
922
name: 'DefaultLogger',
10-
level: isDevelopment ? LogLevel.DEBUG : LogLevel.INFO,
23+
level: logLevel,
1124
pretty: isDevelopment,
1225
disabled: Environment.isTest(),
1326
},
1427
{
1528
environment: Environment.name,
1629
service: 'fortune-exchange-oracle',
30+
version: Environment.version,
1731
},
1832
);
1933

0 commit comments

Comments
 (0)