Skip to content

Commit c88c3d0

Browse files
committed
catch stats error
1 parent 8149c3d commit c88c3d0

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/endpoints/network/network.controller.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { Controller, Get } from '@nestjs/common';
1+
import { Controller, Get, InternalServerErrorException } from '@nestjs/common';
22
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
33
import { NetworkConstants } from './entities/constants';
44
import { Economics } from './entities/economics';
55
import { NetworkService } from './network.service';
66
import { Stats } from 'src/endpoints/network/entities/stats';
77
import { About } from './entities/about';
8+
import { OriginLogger } from '@multiversx/sdk-nestjs-common';
89

910
@Controller()
1011
@ApiTags('network')
1112
export class NetworkController {
13+
private readonly logger = new OriginLogger(NetworkController.name);
1214
constructor(
1315
private readonly networkService: NetworkService
1416
) { }
@@ -31,9 +33,15 @@ export class NetworkController {
3133
@ApiOperation({ summary: 'Network statistics', description: 'Returns general network statistics' })
3234
@ApiOkResponse({ type: Stats })
3335
async getStats(): Promise<Stats> {
34-
return await this.networkService.getStats();
36+
try {
37+
return await this.networkService.getStats();
38+
} catch (error) {
39+
this.logger.error('Error fetching network stats', error);
40+
throw new InternalServerErrorException('Failed to fetch network statistics');
41+
}
3542
}
3643

44+
3745
@Get("/about")
3846
@ApiOperation({ summary: 'About', description: 'Returns general information about API deployment' })
3947
@ApiOkResponse({ type: About })

0 commit comments

Comments
 (0)