Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎨 collected errors and texts into constants #190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/category/exceptions/category-not-found.exception.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { HttpStatus } from '@nestjs/common';
import { TMSException } from 'src/common/exceptions/tms.exception';
import { ERROR_META_DATAS } from 'src/constants';

export default class CategoryNotFoundException extends TMSException {
constructor() {
super('Kategori bulunamadı', HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND);
super(
ERROR_META_DATAS.CATEGORY.NOT_FOUND.message,
ERROR_META_DATAS.CATEGORY.NOT_FOUND.code,
HttpStatus.NOT_FOUND
);
}
}
12 changes: 6 additions & 6 deletions src/common/filters/exception.filter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
ExceptionFilter,
Catch,
ArgumentsHost,
HttpStatus,
Catch,
ExceptionFilter,
HttpException,
HttpStatus,
} from '@nestjs/common';
import { PinoLogger } from 'nestjs-pino';
import { ERROR_MESSAGES } from '../../constants';
import { ERROR_META_DATAS } from '../../constants';
import { TMSException } from '../exceptions/tms.exception';
import ValidationException from '../exceptions/validation.exception';

Expand All @@ -24,7 +24,7 @@ const createTmsErrorResponse = (exception: TMSException) => {
};

const createValidationErrorForResponse = (exception: ValidationException) => {
const { code, error } = ERROR_MESSAGES.VALIDATION;
const { code, error } = ERROR_META_DATAS.COMMON.VALIDATION;
const { constraints, property }: any = exception.getResponse();

const rawConstraints = constraints
Expand All @@ -46,7 +46,7 @@ const createValidationErrorForResponse = (exception: ValidationException) => {
};

const createUnknownErrorResponse = (exception: HttpException) => {
const { code, error, message } = ERROR_MESSAGES.UNKNOWN;
const { code, error, message } = ERROR_META_DATAS.COMMON.UNKNOWN;
const { message: detail, stack } = exception;

return {
Expand Down
156 changes: 143 additions & 13 deletions src/constants/error-messages.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,147 @@
export const ERROR_MESSAGES = {
UNKNOWN: {
error: 'UnknownError',
message: 'unknown error',
code: -1,
/*

Naming Conventions
Path: <Domain>.<ErrorType>.<ErrorMetaData>
Error: <Domain><ErrorType>
Message: User and UI friendly error definition
Code: Unique error id, helpful when searching error at docs

Error Code Collections:
Collection number + Error id itself
Positive 3 digit + Positive 3 digit

Number of Category For each Category
900 (100-999) 900 (100-999) -> 810.000 Posibility


Common 101***
User 102***
SMS 103***
Trip 104***
Integration 105***
Dispatch 106***
Category 107***

*/

export const ERROR_META_DATAS = {
COMMON: {
UNKNOWN: {
error: 'UnknownError',
message: 'unknown error',
code: -1,
},
VALIDATION: {
error: 'ValidationError',
message: 'validation failed',
code: -2,
},
MICROSERVICE: {
error: 'MicroserviceError',
message: 'microservice error',
code: -3,
},
},
VALIDATION: {
error: 'ValidationError',
message: 'validation failed',
code: -2,
USER: {
NOT_FOUND: {
code: 102001,
error: 'UserNotFound', // UserNotFoundException
message: 'Kullanıcı adı veya doğrulama kodu hatalı!',
},
CAN_NOT_BE_ACTIVATED: {
code: 102002,
error: 'UserCanNotBeActivated', // UserCanNotBeActivatedException
message: 'Kullanıcı giriş yapmadan aktif edilemez!',
},
PHONE_NUMBER_ALREADY_EXISTS: {
code: 102003,
error: 'UserPhoneNumberAlreadyExists', // PhoneNumberAlreadyExistsException
message: 'Bu telefon numarası zaten mevcut!',
},
INVALID_VERIFICATION_CODE: {
code: 102004,
error: 'UserInvalidVerificationCode', // InvalidVerificationCodeException
message: 'Doğrulama kodu hatalı.',
},
INVALID_TOKEN: {
code: 102005,
error: 'UserInvalidToken', // InvalidTokenException
message: 'Geçersiz Token.',
},
},
MICROSERVICE: {
error: 'MicroserviceError',
message: 'microservice error',
code: -3,
SMS: {
RESEND_COUNT_EXCEEDED: {
code: 103001,
error: 'SMSResendCountExceeded', // ResendSmsCountExceededException
message: 'SMS limiti aşıldı. Lütfen 5 dakika sonra tekran deneyiniz.',
},
},
TRIP: {
NOT_FOUND: {
code: 104001,
error: 'TripNotFound', // TripNotFoundException
message: 'Yolculuk bulunamadı!',
},
INVALID_LOCATION: {
code: 104002,
error: 'TripInvalidLocation', // TripInvalidLocationException
message: 'Girilen lokasyon bilgisi tanımsız!',
},
INVALID_PRODUCT: {
code: 104003,
error: 'TripInvalidProduct', // TripInvalidProductException
message: 'Girilen ürün bilgisi tanımsız!',
},
INVALID_ORGANIZATION: {
code: 104004,
error: 'TripInvalidOrganization', // TripInvalidOrganizationException
message: 'Organizasyon bulunamadı!',
},
STATUS_NOT_ALLOWED: {
code: 104005,
error: 'TripStatusNotAllowed', // TripStatusNotAllowedException
message: 'Yolculuk icin bu işlem yapılamaz!',
},
DRIVER_NAME_NOT_DEFINED: {
code: 104006,
error: 'TripDriverNameNotDefined', // TripDriverNameNotDefinedException
message: 'Sürücü adı tanımlı değil!',
},
DRIVER_PHONE_NOT_DEFINED: {
code: 104007,
error: 'TripDriverPhoneNotDefined', // TripDriverPhoneNotDefinedException
message: 'Sürücü numarası tanımlı değil!',
},
VEHICLE_PLATE_NOT_DEFINED: {
code: 104008,
error: 'TripVehiclePlateNotDefined', // TripVehiclePlateNotDefinedException
message: 'Araç plakası tanımlı değil!',
},
},
INTEGRATION: {
NOT_FOUND: {
code: 105001,
error: 'IntegrationNotFound', // IntegrationNotFoundException
message: 'Entegrasyon bulunamadı',
},
},
DISPATCH: {
INVALID: {
code: 106001,
error: 'DispatchInvalid', // InvalidDispatchException
message: 'Dispatch datası uygun degil!',
},
INVALID_INTEGRATION: {
code: 106002,
error: 'DispatchInvalidIntegration', // InvalidDispatchIntegrationException
message: 'Dispatch datası için uygun entegrasyon bulunamadı!',
},
},
CATEGORY: {
NOT_FOUND: {
code: 107001,
error: 'CategoryNotFound', // CategoryNotFoundException
message: 'Kategori bulunamadı',
},
},
};
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './error-messages';
export * from './texts';
12 changes: 12 additions & 0 deletions src/constants/texts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*

Naming Conventions
Path: <Domain>.<TextType>
Message: User and UI friendly text
*/

export const TEXTS = {
TRIP: {
messageBody: 'kvkk metni',
},
};
9 changes: 5 additions & 4 deletions src/dispatch/exceptions/dispatch.exceptions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { HttpStatus } from '@nestjs/common';
import { TMSException } from 'src/common/exceptions/tms.exception';
import { ERROR_META_DATAS } from 'src/constants';

export class InvalidDispatchException extends TMSException {
constructor(data?: any) {
super(
'Dispatch datası uygun degil!',
HttpStatus.INTERNAL_SERVER_ERROR,
ERROR_META_DATAS.DISPATCH.INVALID.message,
ERROR_META_DATAS.DISPATCH.INVALID.code,
HttpStatus.INTERNAL_SERVER_ERROR,
data
);
Expand All @@ -15,8 +16,8 @@ export class InvalidDispatchException extends TMSException {
export class InvalidDispatchIntegrationException extends TMSException {
constructor(data?: any) {
super(
'Dispatch datası için uygun entegrasyon bulunamadı!',
HttpStatus.NOT_FOUND,
ERROR_META_DATAS.DISPATCH.INVALID_INTEGRATION.message,
ERROR_META_DATAS.DISPATCH.INVALID_INTEGRATION.code,
HttpStatus.NOT_FOUND,
data
);
Expand Down
5 changes: 3 additions & 2 deletions src/integration/exceptions/integration.exceptions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { HttpStatus } from '@nestjs/common';
import { TMSException } from 'src/common/exceptions/tms.exception';
import { ERROR_META_DATAS } from 'src/constants';

export class IntegrationNotFoundException extends TMSException {
constructor(data?: any) {
super(
'Entegrasyon bulunamadı',
HttpStatus.NOT_FOUND,
ERROR_META_DATAS.INTEGRATION.NOT_FOUND.message,
ERROR_META_DATAS.INTEGRATION.NOT_FOUND.code,
HttpStatus.NOT_FOUND,
data
);
Expand Down
35 changes: 20 additions & 15 deletions src/trip/exceptions/trip.exception.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { HttpStatus } from '@nestjs/common';
import { TMSException } from 'src/common/exceptions/tms.exception';
import { ERROR_META_DATAS } from 'src/constants';

export class TripNotFoundException extends TMSException {
constructor() {
super('Yolculuk bulunamadı!', HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND);
super(
ERROR_META_DATAS.TRIP.NOT_FOUND.message,
ERROR_META_DATAS.TRIP.NOT_FOUND.code,
HttpStatus.NOT_FOUND
);
}
}

export class TripInvalidLocationException extends TMSException {
constructor(data?: any) {
super(
'Girilen lokasyon bilgisi tanımsız!',
HttpStatus.BAD_REQUEST,
ERROR_META_DATAS.TRIP.INVALID_LOCATION.message,
ERROR_META_DATAS.TRIP.INVALID_LOCATION.code,
HttpStatus.BAD_REQUEST,
data
);
Expand All @@ -21,8 +26,8 @@ export class TripInvalidLocationException extends TMSException {
export class TripInvalidProductException extends TMSException {
constructor(data?: any) {
super(
'Girilen ürün bilgisi tanımsız!',
HttpStatus.BAD_REQUEST,
ERROR_META_DATAS.TRIP.INVALID_PRODUCT.message,
ERROR_META_DATAS.TRIP.INVALID_PRODUCT.code,
HttpStatus.BAD_REQUEST,
data
);
Expand All @@ -32,8 +37,8 @@ export class TripInvalidProductException extends TMSException {
export class TripInvalidOrganizationExcetion extends TMSException {
constructor(data?: any) {
super(
'Organizasyon bulunamadı!',
HttpStatus.NOT_FOUND,
ERROR_META_DATAS.TRIP.INVALID_ORGANIZATION.message,
ERROR_META_DATAS.TRIP.INVALID_ORGANIZATION.code,
HttpStatus.NOT_FOUND,
data
);
Expand All @@ -43,8 +48,8 @@ export class TripInvalidOrganizationExcetion extends TMSException {
export class TripStatusNotAllowedException extends TMSException {
constructor(data?: any) {
super(
'Yolculuk icin bu işlem yapılamaz!',
HttpStatus.BAD_REQUEST,
ERROR_META_DATAS.TRIP.STATUS_NOT_ALLOWED.message,
ERROR_META_DATAS.TRIP.STATUS_NOT_ALLOWED.code,
HttpStatus.BAD_REQUEST,
data
);
Expand All @@ -54,8 +59,8 @@ export class TripStatusNotAllowedException extends TMSException {
export class TripDriverNameNotDefinedException extends TMSException {
constructor(data?: any) {
super(
'Sürücü adı tanımlı değil!',
HttpStatus.BAD_REQUEST,
ERROR_META_DATAS.TRIP.DRIVER_NAME_NOT_DEFINED.message,
ERROR_META_DATAS.TRIP.DRIVER_NAME_NOT_DEFINED.code,
HttpStatus.BAD_REQUEST,
data
);
Expand All @@ -65,8 +70,8 @@ export class TripDriverNameNotDefinedException extends TMSException {
export class TripDriverPhoneNotDefinedException extends TMSException {
constructor(data?: any) {
super(
'Sürücü numarası tanımlı değil!',
HttpStatus.BAD_REQUEST,
ERROR_META_DATAS.TRIP.DRIVER_PHONE_NOT_DEFINED.message,
ERROR_META_DATAS.TRIP.DRIVER_PHONE_NOT_DEFINED.code,
HttpStatus.BAD_REQUEST,
data
);
Expand All @@ -76,8 +81,8 @@ export class TripDriverPhoneNotDefinedException extends TMSException {
export class TripVehiclePlateNotDefinedException extends TMSException {
constructor(data?: any) {
super(
'Araç plakası tanımlı değil!',
HttpStatus.BAD_REQUEST,
ERROR_META_DATAS.TRIP.VEHICLE_PLATE_NOT_DEFINED.message,
ERROR_META_DATAS.TRIP.VEHICLE_PLATE_NOT_DEFINED.code,
HttpStatus.BAD_REQUEST,
data
);
Expand Down
Loading