fix(lint): clean up type definitions and missing imports
Deploy Canina / deploy (push) Failing after 30m46s

This commit is contained in:
parsa aghaei committed 2026-07-29 16:44:53 +03:30
1 parent 9c8286c63f
commit 2de442dbae
9 files changed
+147 -62

No files matched your search

@@ -19,9 +19,10 @@ export class CustomHttpExceptionFilter implements ExceptionFilter {
const request = ctx.getRequest<Request>();
let status = HttpStatus.INTERNAL_SERVER_ERROR;
let message = 'خطای داخلی سرور رخ داده است. لطفاً بعداً تلاش کنید یا با پشتیبانی تماس بگیرید.';
let message =
'خطای داخلی سرور رخ داده است. لطفاً بعداً تلاش کنید یا با پشتیبانی تماس بگیرید.';
let code = 'INTERNAL_SERVER_ERROR';
let details: ErrorDetailField[] | Record<string, any> = {};
let details: ErrorDetailField[] | Record<string, unknown> = {};
if (exception instanceof HttpException) {
status = exception.getStatus();
@@ -30,14 +31,17 @@ export class CustomHttpExceptionFilter implements ExceptionFilter {
if (typeof exceptionResponse === 'string') {
message = this.translateGenericMessage(exceptionResponse, status);
code = this.deriveErrorCode(status, exceptionResponse);
} else if (typeof exceptionResponse === 'object' && exceptionResponse !== null) {
const resObj = exceptionResponse as Record<string, any>;
} else if (
typeof exceptionResponse === 'object' &&
exceptionResponse !== null
) {
const resObj = exceptionResponse as Record<string, unknown>;
// Handle class-validator validation array messages
if (Array.isArray(resObj.message)) {
message = 'اطلاعات وارد شده نامعتبر است. لطفاً فرم را بررسی کنید.';
code = 'INVALID_INPUT_DATA';
details = resObj.message.map((msg: string) => {
details = (resObj.message as string[]).map((msg: string) => {
const parts = msg.split(' ');
return {
field: parts[0] || 'general',
@@ -45,13 +49,19 @@ export class CustomHttpExceptionFilter implements ExceptionFilter {
};
});
} else {
message = this.translateGenericMessage(resObj.message || exception.message, status);
code = resObj.code || this.deriveErrorCode(status, resObj.error);
details = resObj.details || {};
const rawMsg = typeof resObj.message === 'string' ? resObj.message : exception.message;
message = this.translateGenericMessage(rawMsg, status);
const rawCode = typeof resObj.code === 'string' ? resObj.code : undefined;
const rawError = typeof resObj.error === 'string' ? resObj.error : undefined;
code = rawCode || this.deriveErrorCode(status, rawError);
details = (resObj.details as Record<string, unknown>) || {};
}
}
} else if (exception instanceof Error) {
this.logger.error(`Unhandled Exception: ${exception.message}`, exception.stack);
this.logger.error(
`Unhandled Exception: ${exception.message}`,
exception.stack,
);
message = 'خطای غیرمنتظره در پردازش درخواست رخ داد.';
code = 'UNHANDLED_EXCEPTION';
}
@@ -66,14 +76,16 @@ export class CustomHttpExceptionFilter implements ExceptionFilter {
path: request.url,
};
this.logger.warn(`[${request.method}] ${request.url} - Status ${status} - ${message}`);
this.logger.warn(
`[${request.method}] ${request.url} - Status ${status} - ${message}`,
);
response.status(status).json(errorPayload);
}
private translateGenericMessage(msg: string, status: number): string {
if (!msg) return 'خطای نامشخص رخ داده است.';
const lower = msg.toLowerCase();
if (lower.includes('unauthorized') || status === 401) {
return 'شما دسترسی لازم برای این عملیات را ندارید. لطفاً ابتدا وارد حساب کاربری خود شوید.';
@@ -100,14 +112,22 @@ export class CustomHttpExceptionFilter implements ExceptionFilter {
}
switch (status) {
case 400: return 'BAD_REQUEST';
case 401: return 'UNAUTHORIZED';
case 403: return 'FORBIDDEN';
case 404: return 'NOT_FOUND';
case 409: return 'CONFLICT';
case 422: return 'UNPROCESSABLE_ENTITY';
case 429: return 'TOO_MANY_REQUESTS';
default: return 'INTERNAL_SERVER_ERROR';
case 400:
return 'BAD_REQUEST';
case 401:
return 'UNAUTHORIZED';
case 403:
return 'FORBIDDEN';
case 404:
return 'NOT_FOUND';
case 409:
return 'CONFLICT';
case 422:
return 'UNPROCESSABLE_ENTITY';
case 429:
return 'TOO_MANY_REQUESTS';
default:
return 'INTERNAL_SERVER_ERROR';
}
}
}
@@ -20,7 +20,7 @@ export class PrismaExceptionFilter implements ExceptionFilter {
let status = HttpStatus.BAD_REQUEST;
let message = 'خطایی در پردازش اطلاعات دیتابیس رخ داده است.';
let code = `PRISMA_${exception.code}`;
let details: Record<string, any> = {};
let details: Record<string, unknown> = {};
switch (exception.code) {
case 'P2002': {
@@ -34,14 +34,16 @@ export class PrismaExceptionFilter implements ExceptionFilter {
}
case 'P2025': {
status = HttpStatus.NOT_FOUND;
message = 'اطلاعات یا رکورد مورد نظر در سیستم یافت نشد یا قبلاً حذف شده است.';
message =
'اطلاعات یا رکورد مورد نظر در سیستم یافت نشد یا قبلاً حذف شده است.';
code = 'RECORD_NOT_FOUND';
details = { meta: exception.meta };
break;
}
case 'P2003': {
status = HttpStatus.BAD_REQUEST;
message = 'امکان انجام عملیات به دلیل وجود وابستگی بین اطلاعات وجود ندارد.';
message =
'امکان انجام عملیات به دلیل وجود وابستگی بین اطلاعات وجود ندارد.';
code = 'FOREIGN_KEY_CONSTRAINT_FAILED';
break;
}
@@ -52,7 +54,9 @@ export class PrismaExceptionFilter implements ExceptionFilter {
}
}
this.logger.error(`[Prisma ${exception.code}] ${request.method} ${request.url} - ${message}`);
this.logger.error(
`[Prisma ${exception.code}] ${request.method} ${request.url} - ${message}`,
);
response.status(status).json({
success: false,
@@ -4,12 +4,18 @@ export class ErrorDetailField {
@ApiProperty({ description: 'نام فیلد دارای خطا', example: 'phone' })
field: string;
@ApiProperty({ description: 'توضیح توصیفی خطا به فارسی', example: 'شماره تلفن همراه وارد شده نامعتبر است.' })
@ApiProperty({
description: 'توضیح توصیفی خطا به فارسی',
example: 'شماره تلفن همراه وارد شده نامعتبر است.',
})
message: string;
}
export class ApiErrorResponse {
@ApiProperty({ description: 'وضعیت موفقیت درخواست (همیشه false در زمان خطا)', example: false })
@ApiProperty({
description: 'وضعیت موفقیت درخواست (همیشه false در زمان خطا)',
example: false,
})
success: boolean;
@ApiProperty({ description: 'کد وضعیت HTTP درخواست', example: 400 })
@@ -17,11 +23,15 @@ export class ApiErrorResponse {
@ApiProperty({
description: 'پیام جامع و توصیفی خطا به زبان فارسی',
example: 'اطلاعات وارد شده نامعتبر است. لطفاً موارد مشخص شده را بررسی نمایید.',
example:
'اطلاعات وارد شده نامعتبر است. لطفاً موارد مشخص شده را بررسی نمایید.',
})
message: string;
@ApiProperty({ description: 'کد سیستمیک و ثابت خطا جهت پردازش فرانت‌اند', example: 'INVALID_INPUT_DATA' })
@ApiProperty({
description: 'کد سیستمیک و ثابت خطا جهت پردازش فرانت‌اند',
example: 'INVALID_INPUT_DATA',
})
code: string;
@ApiProperty({
@@ -31,9 +41,15 @@ export class ApiErrorResponse {
})
details?: ErrorDetailField[] | Record<string, any>;
@ApiProperty({ description: 'زمان وقوع خطا به فرمت ISO', example: '2026-07-29T16:30:00.000Z' })
@ApiProperty({
description: 'زمان وقوع خطا به فرمت ISO',
example: '2026-07-29T16:30:00.000Z',
})
timestamp: string;
@ApiProperty({ description: 'مسیر و انکوینتی که خطا در آن رخ داده است', example: '/api/auth/register' })
@ApiProperty({
description: 'مسیر و انکوینتی که خطا در آن رخ داده است',
example: '/api/auth/register',
})
path: string;
}
+26 -6
View File
@@ -68,7 +68,9 @@ export class SmsService {
);
req.on('error', (err) => {
this.logger.error(`[SMS Exception] MeliPayamak HTTP Error: ${err.message}`);
this.logger.error(
`[SMS Exception] MeliPayamak HTTP Error: ${err.message}`,
);
resolve(false);
});
@@ -92,7 +94,11 @@ export class SmsService {
/**
* Send Order Confirmation SMS
*/
async sendOrderConfirmation(phone: string, orderNumber: string, amount: string): Promise<boolean> {
async sendOrderConfirmation(
phone: string,
orderNumber: string,
amount: string,
): Promise<boolean> {
const bodyId = parseInt(process.env.MELIPAYAMAK_ORDER_BODY_ID || '0', 10);
return this.sendPatternSms({
to: phone,
@@ -104,8 +110,15 @@ export class SmsService {
/**
* Send Shipping Status SMS with Tracking Code
*/
async sendShippingNotification(phone: string, orderNumber: string, trackingCode: string): Promise<boolean> {
const bodyId = parseInt(process.env.MELIPAYAMAK_SHIPPING_BODY_ID || '0', 10);
async sendShippingNotification(
phone: string,
orderNumber: string,
trackingCode: string,
): Promise<boolean> {
const bodyId = parseInt(
process.env.MELIPAYAMAK_SHIPPING_BODY_ID || '0',
10,
);
return this.sendPatternSms({
to: phone,
bodyId,
@@ -116,8 +129,15 @@ export class SmsService {
/**
* Send Pet Care Vaccination / Deworming Reminder SMS
*/
async sendPetCareReminder(phone: string, petName: string, reminderType: string): Promise<boolean> {
const bodyId = parseInt(process.env.MELIPAYAMAK_PET_CARE_BODY_ID || '0', 10);
async sendPetCareReminder(
phone: string,
petName: string,
reminderType: string,
): Promise<boolean> {
const bodyId = parseInt(
process.env.MELIPAYAMAK_PET_CARE_BODY_ID || '0',
10,
);
return this.sendPatternSms({
to: phone,
bodyId,