modified for res code
This commit is contained in:
parent
ecb9974f03
commit
b6e13398bd
@ -8,12 +8,12 @@ export class BadRequestException extends HttpException {
|
|||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
statusCode: HttpStatus.BAD_REQUEST ,
|
||||||
message,
|
message,
|
||||||
// errorCode,
|
// errorCode,
|
||||||
// data,
|
// data,
|
||||||
},
|
},
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
HttpStatus.BAD_REQUEST,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
|
||||||
ValidationError,
|
ValidationError,
|
||||||
ValidationPipe,
|
ValidationPipe,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
||||||
import { SwaggerDocumentOptions } from '@nestjs/swagger';
|
import { SwaggerDocumentOptions } from '@nestjs/swagger';
|
||||||
|
import { BadRequestException } from './exceptions/badRequest.exception';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule, {
|
const app = await NestFactory.create(AppModule, {
|
||||||
@ -56,10 +56,7 @@ async function bootstrap() {
|
|||||||
})
|
})
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
throw new BadRequestException({
|
throw new BadRequestException(newResult[0].message);
|
||||||
message: 'Validation failed',
|
|
||||||
errors: newResult,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
app.useGlobalPipes(
|
app.useGlobalPipes(
|
||||||
@ -77,11 +74,11 @@ async function bootstrap() {
|
|||||||
.setTitle('API')
|
.setTitle('API')
|
||||||
.setDescription('API description')
|
.setDescription('API description')
|
||||||
.setVersion('1.0')
|
.setVersion('1.0')
|
||||||
.addServer('http://localhost:3000', 'Development Server 1')
|
|
||||||
.addServer(
|
.addServer(
|
||||||
'https://dev.alphaomegainfosys.com/test-api',
|
'https://dev.alphaomegainfosys.com/test-api',
|
||||||
'Development Server 2',
|
'Development Server 2',
|
||||||
)
|
)
|
||||||
|
.addServer('http://localhost:3000', 'Development Server 1')
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const options: SwaggerDocumentOptions = {
|
const options: SwaggerDocumentOptions = {
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import {
|
|||||||
UpdateCsFeeDTO,
|
UpdateCsFeeDTO,
|
||||||
UpdateEfFeeDTO,
|
UpdateEfFeeDTO,
|
||||||
UpdateFeeCommBodyDTO,
|
UpdateFeeCommBodyDTO,
|
||||||
|
UpdateFeeCommDTO,
|
||||||
} from './manage-fee.dto';
|
} from './manage-fee.dto';
|
||||||
|
|
||||||
@Controller('oracle')
|
@Controller('oracle')
|
||||||
@ -145,7 +146,7 @@ export class ManageFeeController {
|
|||||||
|
|
||||||
@ApiTags('Manage Fee - Oracle')
|
@ApiTags('Manage Fee - Oracle')
|
||||||
@Patch('/UpdateFeeComm')
|
@Patch('/UpdateFeeComm')
|
||||||
UpdateFeeComm(@Body() body: UpdateFeeCommBodyDTO) {
|
UpdateFeeComm(@Body() body: UpdateFeeCommDTO) {
|
||||||
return this.manageFeeService.UPDATEFEECOMM(body);
|
return this.manageFeeService.UPDATEFEECOMM(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -40,16 +40,16 @@ export class InsertNewServiceProviderDTO {
|
|||||||
@IsDefined({ message: 'Property p_state is required' })
|
@IsDefined({ message: 'Property p_state is required' })
|
||||||
p_state: string;
|
p_state: string;
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
|
||||||
@IsString({ message: 'Property p_zip must be a string' })
|
|
||||||
@IsDefined({ message: 'Property p_zip is required' })
|
|
||||||
p_zip: string;
|
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@IsString({ message: 'Property p_country must be a string' })
|
@IsString({ message: 'Property p_country must be a string' })
|
||||||
@IsDefined({ message: 'Property p_country is required' })
|
@IsDefined({ message: 'Property p_country is required' })
|
||||||
p_country: string;
|
p_country: string;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@IsString({ message: 'Property p_zip must be a string' })
|
||||||
|
@IsDefined({ message: 'Property p_zip is required' })
|
||||||
|
p_zip: string;
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@IsString({ message: 'Property p_issuingregion must be a string' })
|
@IsString({ message: 'Property p_issuingregion must be a string' })
|
||||||
@IsDefined({ message: 'Property p_issuingregion is required' })
|
@IsDefined({ message: 'Property p_issuingregion is required' })
|
||||||
@ -127,11 +127,6 @@ export class UpdateServiceProviderDTO {
|
|||||||
@IsDefined({ message: 'Property p_state is required' })
|
@IsDefined({ message: 'Property p_state is required' })
|
||||||
p_state: string;
|
p_state: string;
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
|
||||||
@IsString({ message: 'Property p_zip must be a string' })
|
|
||||||
@IsDefined({ message: 'Property p_zip is required' })
|
|
||||||
p_zip: string;
|
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@IsString({ message: 'Property p_country must be a string' })
|
@IsString({ message: 'Property p_country must be a string' })
|
||||||
@IsDefined({ message: 'Property p_country is required' })
|
@IsDefined({ message: 'Property p_country is required' })
|
||||||
@ -162,6 +157,11 @@ export class UpdateServiceProviderDTO {
|
|||||||
@IsDefined({ message: 'Property p_cargosurety is required' })
|
@IsDefined({ message: 'Property p_cargosurety is required' })
|
||||||
p_cargosurety: string;
|
p_cargosurety: string;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@IsString({ message: 'Property p_zip must be a string' })
|
||||||
|
@IsDefined({ message: 'Property p_zip is required' })
|
||||||
|
p_zip: string;
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@IsString({ message: 'Property p_user_id must be a string' })
|
@IsString({ message: 'Property p_user_id must be a string' })
|
||||||
@IsDefined({ message: 'Property p_user_id is required' })
|
@IsDefined({ message: 'Property p_user_id is required' })
|
||||||
@ -176,6 +176,7 @@ export class UpdateServiceProviderDTO {
|
|||||||
@IsString({ message: 'Property P_FILEIDS must be a string' })
|
@IsString({ message: 'Property P_FILEIDS must be a string' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
P_FILEIDS?: string;
|
P_FILEIDS?: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class getSelectedServiceproviderDTO {
|
export class getSelectedServiceproviderDTO {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { OracleDBService } from 'src/db/db.service';
|
import { OracleDBService } from 'src/db/db.service';
|
||||||
import * as oracledb from 'oracledb';
|
import * as oracledb from 'oracledb';
|
||||||
import {
|
import {
|
||||||
@ -6,9 +6,13 @@ import {
|
|||||||
InsertNewServiceProviderDTO,
|
InsertNewServiceProviderDTO,
|
||||||
UpdateServiceProviderDTO,
|
UpdateServiceProviderDTO,
|
||||||
} from './sp.dto';
|
} from './sp.dto';
|
||||||
|
import { BadRequestException } from 'src/exceptions/badRequest.exception';
|
||||||
|
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SpService {
|
export class SpService {
|
||||||
|
private readonly logger = new Logger(SpService.name);
|
||||||
|
|
||||||
constructor(private readonly oracleDBService: OracleDBService) { }
|
constructor(private readonly oracleDBService: OracleDBService) { }
|
||||||
|
|
||||||
async insertNewServiceProvider(body: InsertNewServiceProviderDTO) {
|
async insertNewServiceProvider(body: InsertNewServiceProviderDTO) {
|
||||||
@ -16,7 +20,8 @@ export class SpService {
|
|||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
throw new Error('No DB Connected');
|
this.logger.error(`Database connection failed`);
|
||||||
|
throw new InternalServerException();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await connection.execute(
|
const result = await connection.execute(
|
||||||
@ -119,31 +124,74 @@ export class SpService {
|
|||||||
|
|
||||||
const fres = await result.outBinds.p_cursor.getRows();
|
const fres = await result.outBinds.p_cursor.getRows();
|
||||||
|
|
||||||
|
if (fres[0].ERRORMESG) {
|
||||||
|
console.log(fres[0].ERRORMESG);
|
||||||
|
throw new BadRequestException(fres[0].ERRORMESG)
|
||||||
|
}
|
||||||
|
|
||||||
return fres;
|
return fres;
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
if (err instanceof Error) {
|
if (error instanceof BadRequestException) {
|
||||||
return { error: err.message };
|
throw error;
|
||||||
} else {
|
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
}
|
||||||
|
else if (error.message === "NJS-107: invalid cursor") {
|
||||||
|
throw new BadRequestException();
|
||||||
}
|
}
|
||||||
finally {
|
this.logger.error('insertNewServiceProvider failed', error.stack || error);
|
||||||
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateServiceProvider(body: UpdateServiceProviderDTO) {
|
async updateServiceProvider(body: UpdateServiceProviderDTO) {
|
||||||
|
|
||||||
|
const newBody = {
|
||||||
|
p_spid: null,
|
||||||
|
p_name: null,
|
||||||
|
p_lookupcode: null,
|
||||||
|
p_address1: null,
|
||||||
|
p_address2: null,
|
||||||
|
p_city: null,
|
||||||
|
p_state: null,
|
||||||
|
p_zip: null,
|
||||||
|
p_country: null,
|
||||||
|
p_issuingregion: null,
|
||||||
|
p_replacementregion: null,
|
||||||
|
p_bondsurety: null,
|
||||||
|
p_cargopolicyno: null,
|
||||||
|
p_cargosurety: null,
|
||||||
|
p_user_id: null
|
||||||
|
};
|
||||||
|
|
||||||
|
const reqBody = JSON.parse(JSON.stringify(body));
|
||||||
|
|
||||||
|
function setEmptyStringsToNull(obj) {
|
||||||
|
Object.keys(obj).forEach((key) => {
|
||||||
|
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
||||||
|
setEmptyStringsToNull(obj[key]);
|
||||||
|
} else if (obj[key] === '') {
|
||||||
|
obj[key] = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setEmptyStringsToNull(reqBody);
|
||||||
|
|
||||||
|
const finalBody: UpdateServiceProviderDTO = { ...newBody, ...reqBody };
|
||||||
|
|
||||||
let connection;
|
let connection;
|
||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
throw new Error('No DB Connected');
|
this.logger.error(`Database connection failed`);
|
||||||
|
throw new InternalServerException();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await connection.execute(
|
const result = await connection.execute(
|
||||||
@ -170,71 +218,71 @@ export class SpService {
|
|||||||
END;`,
|
END;`,
|
||||||
{
|
{
|
||||||
p_spid: {
|
p_spid: {
|
||||||
val: body.p_spid,
|
val: finalBody.p_spid,
|
||||||
type: oracledb.DB_TYPE_NUMBER,
|
type: oracledb.DB_TYPE_NUMBER,
|
||||||
},
|
},
|
||||||
p_name: {
|
p_name: {
|
||||||
val: body.p_name,
|
val: finalBody.p_name,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_lookupcode: {
|
p_lookupcode: {
|
||||||
val: body.p_lookupcode,
|
val: finalBody.p_lookupcode,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_address1: {
|
p_address1: {
|
||||||
val: body.p_address1,
|
val: finalBody.p_address1,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_address2: {
|
p_address2: {
|
||||||
val: body.p_address2,
|
val: finalBody.p_address2,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_city: {
|
p_city: {
|
||||||
val: body.p_city,
|
val: finalBody.p_city,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_state: {
|
p_state: {
|
||||||
val: body.p_state,
|
val: finalBody.p_state,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_zip: {
|
p_zip: {
|
||||||
val: body.p_zip,
|
val: finalBody.p_zip,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_country: {
|
p_country: {
|
||||||
val: body.p_country,
|
val: finalBody.p_country,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_issuingregion: {
|
p_issuingregion: {
|
||||||
val: body.p_issuingregion,
|
val: finalBody.p_issuingregion,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_replacementregion: {
|
p_replacementregion: {
|
||||||
val: body.p_replacementregion,
|
val: finalBody.p_replacementregion,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_bondsurety: {
|
p_bondsurety: {
|
||||||
val: body.p_bondsurety,
|
val: finalBody.p_bondsurety,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_cargopolicyno: {
|
p_cargopolicyno: {
|
||||||
val: body.p_cargopolicyno,
|
val: finalBody.p_cargopolicyno,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_cargosurety: {
|
p_cargosurety: {
|
||||||
val: body.p_cargosurety,
|
val: finalBody.p_cargosurety,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_user_id: {
|
p_user_id: {
|
||||||
val: body.p_user_id,
|
val: finalBody.p_user_id,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
P_NOTES: {
|
P_NOTES: {
|
||||||
val: body.P_NOTES,
|
val: finalBody.P_NOTES,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
P_FILEIDS: {
|
P_FILEIDS: {
|
||||||
val: body.P_FILEIDS,
|
val: finalBody.P_FILEIDS,
|
||||||
type: oracledb.DB_TYPE_VARCHAR,
|
type: oracledb.DB_TYPE_VARCHAR,
|
||||||
},
|
},
|
||||||
p_cursor: {
|
p_cursor: {
|
||||||
@ -251,20 +299,27 @@ export class SpService {
|
|||||||
|
|
||||||
const fres = await result.outBinds.p_cursor.getRows();
|
const fres = await result.outBinds.p_cursor.getRows();
|
||||||
|
|
||||||
|
if (fres[0].ERRORMESG) {
|
||||||
|
console.log(fres[0].ERRORMESG);
|
||||||
|
throw new BadRequestException(fres[0].ERRORMESG)
|
||||||
|
}
|
||||||
|
|
||||||
return fres;
|
return fres;
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
if (err instanceof Error) {
|
if (error instanceof BadRequestException) {
|
||||||
return { error: err.message };
|
throw error;
|
||||||
} else {
|
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
}
|
||||||
|
else if (error.message === "NJS-107: invalid cursor") {
|
||||||
|
throw new BadRequestException();
|
||||||
}
|
}
|
||||||
finally {
|
this.logger.error('updateServiceProvider failed', error.stack || error);
|
||||||
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,11 +327,12 @@ export class SpService {
|
|||||||
|
|
||||||
async getAllServiceproviders() {
|
async getAllServiceproviders() {
|
||||||
let connection;
|
let connection;
|
||||||
let rows = [];
|
let rows: any = [];
|
||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
throw new Error('No DB Connected');
|
this.logger.error(`Database connection failed`);
|
||||||
|
throw new InternalServerException();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await connection.execute(
|
const result = await connection.execute(
|
||||||
@ -305,23 +361,30 @@ export class SpService {
|
|||||||
|
|
||||||
await cursor.close();
|
await cursor.close();
|
||||||
|
|
||||||
|
if (rows.length > 0 && rows[0].ERRORMESG) {
|
||||||
|
this.logger.warn(`error from DB: ${rows[0].ERRORMESG}`);
|
||||||
|
throw new BadRequestException(rows[0].ERRORMESG);
|
||||||
|
}
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('No cursor returned from the stored procedure');
|
throw new BadRequestException();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
if (err instanceof Error) {
|
if (error instanceof BadRequestException) {
|
||||||
return { error: err.message };
|
throw error;
|
||||||
} else {
|
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
}
|
||||||
|
else if (error.message === "NJS-107: invalid cursor") {
|
||||||
|
throw new BadRequestException();
|
||||||
}
|
}
|
||||||
finally {
|
this.logger.error('getAllServiceproviders failed', error.stack || error);
|
||||||
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,11 +392,12 @@ export class SpService {
|
|||||||
|
|
||||||
async getServiceproviderByID(body: getSelectedServiceproviderDTO) {
|
async getServiceproviderByID(body: getSelectedServiceproviderDTO) {
|
||||||
let connection;
|
let connection;
|
||||||
let rows = [];
|
let rows: any = [];
|
||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
throw new Error('No DB Connected');
|
this.logger.error(`Database connection failed`);
|
||||||
|
throw new InternalServerException();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await connection.execute(
|
const result = await connection.execute(
|
||||||
@ -366,23 +430,30 @@ export class SpService {
|
|||||||
|
|
||||||
await cursor.close();
|
await cursor.close();
|
||||||
} else {
|
} else {
|
||||||
throw new Error('No cursor returned from the stored procedure');
|
throw new BadRequestException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rows.length > 0 && rows[0].ERRORMESG) {
|
||||||
|
this.logger.warn(`error from DB: ${rows[0].ERRORMESG}`);
|
||||||
|
throw new BadRequestException(rows[0].ERRORMESG);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
if (err instanceof Error) {
|
if (error instanceof BadRequestException) {
|
||||||
return { error: err.message };
|
throw error;
|
||||||
} else {
|
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
}
|
||||||
|
else if (error.message === "NJS-107: invalid cursor") {
|
||||||
|
throw new BadRequestException();
|
||||||
}
|
}
|
||||||
finally {
|
this.logger.error('getServiceproviderByID failed', error.stack || error);
|
||||||
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user