implementation of exception handling
This commit is contained in:
parent
0cf1727029
commit
81945f66c4
19
src/exceptions/internalServerError.exception.ts
Normal file
19
src/exceptions/internalServerError.exception.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||
|
||||
export class InternalServerException extends HttpException {
|
||||
constructor(
|
||||
message = 'Internal server error',
|
||||
errorCode = 'INTERNAL_ERROR',
|
||||
data: any = null,
|
||||
) {
|
||||
super(
|
||||
{
|
||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
message,
|
||||
// errorCode,
|
||||
// data,
|
||||
},
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
import { Body, Controller, Get, Patch, Post } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { RegionService } from './region.service';
|
||||
import { InsertRegionsDto, UpdateRegionDto } from 'src/oracle/uscib-managed-sp/region/region.dto';
|
||||
import { InsertRegionsDto, RegionDto, UpdateRegionDto } from 'src/oracle/uscib-managed-sp/region/region.dto';
|
||||
|
||||
@Controller('mssql')
|
||||
export class RegionController {
|
||||
@ -9,6 +9,12 @@ export class RegionController {
|
||||
constructor(private readonly regionService: RegionService) { }
|
||||
|
||||
@ApiTags('Regions - Mssql')
|
||||
@ApiOperation({ summary: 'Get all regions for issuing and replacement.' })
|
||||
@ApiOkResponse({
|
||||
description: 'User retrieved successfully',
|
||||
type: RegionDto,
|
||||
})
|
||||
@ApiInternalServerErrorResponse({ description: 'Server error' })
|
||||
@Get('/GetRegions')
|
||||
getRegions() {
|
||||
return this.regionService.getRegions();
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
||||
import { Connection, Request } from 'mssql';
|
||||
import { MssqlDBService } from 'src/db/db.service';
|
||||
import { InsertRegionsDto, UpdateRegionDto } from 'src/oracle/uscib-managed-sp/region/region.dto';
|
||||
import * as mssql from 'mssql';
|
||||
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
|
||||
|
||||
@Injectable()
|
||||
export class RegionService {
|
||||
@ -16,11 +17,8 @@ export class RegionService {
|
||||
const request = new Request(connection);
|
||||
const result = await request.execute('carnetsys.GETREGIONS');
|
||||
return { data: result.recordset };
|
||||
|
||||
} catch (error) {
|
||||
console.log("Error is here ...");
|
||||
|
||||
return { error: error.message };
|
||||
throw new InternalServerException();
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +34,7 @@ export class RegionService {
|
||||
return { data: result.recordset };
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
throw new InternalServerException();
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +49,7 @@ export class RegionService {
|
||||
return { data: result.recordset };
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
throw new InternalServerException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import * as oracledb from 'oracledb';
|
||||
import { OracleDBService } from 'src/db/db.service';
|
||||
import {
|
||||
@ -75,6 +75,9 @@ export class ManageFeeService {
|
||||
return rows;
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
if(err.message === "NJS-107: invalid cursor"){
|
||||
throw new BadRequestException("Bad Request")
|
||||
}
|
||||
return { error: err.message };
|
||||
} else {
|
||||
return { error: 'An unknown error occurred' };
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { IsDefined, IsNumber, IsString } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsDefined, IsInt, IsNumber, IsOptional, IsString } from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
|
||||
export class InsertRegionsDto {
|
||||
@ApiProperty({ required: true })
|
||||
@ -24,3 +24,22 @@ export class UpdateRegionDto {
|
||||
@IsDefined({ message: 'Property p_name is required' })
|
||||
p_name: string;
|
||||
}
|
||||
|
||||
export class RegionDto {
|
||||
@ApiProperty({ example: 1, description: 'Unique identifier for the region' })
|
||||
@IsInt()
|
||||
REGIONID: number;
|
||||
|
||||
@ApiProperty({ example: '01', description: 'Region code' })
|
||||
@IsString()
|
||||
REGION: string;
|
||||
|
||||
@ApiProperty({ example: 'uk', description: 'Human-readable region name' })
|
||||
@IsString()
|
||||
REGIONNAME: string;
|
||||
|
||||
@ApiPropertyOptional({ example: null, description: 'Error message if applicable' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
ERRORMESG?: string | null;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user