diff --git a/sections/errorhandling/operationalvsprogrammererror.russian.md b/sections/errorhandling/operationalvsprogrammererror.russian.md index b4942cb1..544dbd3c 100644 --- a/sections/errorhandling/operationalvsprogrammererror.russian.md +++ b/sections/errorhandling/operationalvsprogrammererror.russian.md @@ -6,9 +6,12 @@ ### Пример кода - пометка ошибки как рабочей (доверенной) +
+Javascript + ```javascript // marking an error object as operational -const myError = new Error("How can I add new product when no value provided?"); +const myError = new Error('How can I add new product when no value provided?'); myError.isOperational = true; // or if you're using some centralized error factory (see other examples at the bullet "Use only the built-in Error object") @@ -22,9 +25,37 @@ class AppError { } }; -throw new AppError(errorManagement.commonErrors.InvalidInput, "Describe here what happened", true); +throw new AppError(errorManagement.commonErrors.InvalidInput, 'Describe here what happened', true); ``` +
+ +
+Typescript + +```typescript +// some centralized error factory (see other examples at the bullet "Use only the built-in Error object") +export class AppError extends Error { + public readonly commonType: string; + public readonly isOperational: boolean; + + constructor(commonType: string, description: string, isOperational: boolean) { + super(description); + + Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain + + this.commonType = commonType; + this.isOperational = isOperational; + + Error.captureStackTrace(this); + } +} + +// marking an error object as operational (true) +throw new AppError(errorManagement.commonErrors.InvalidInput, 'Describe here what happened', true); + +``` +
### Цитата блога: "Ошибки программиста - это ошибки в программе"