Reflecion of #584

This commit is contained in:
Alex Ivanov
2019-11-29 08:13:34 +03:00
parent 2aa77ac538
commit b04b924d39

View File

@ -6,9 +6,12 @@
### Пример кода - пометка ошибки как рабочей (доверенной)
<details>
<summary><strong>Javascript</strong></summary>
```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);
```
</details>
<details>
<summary><strong>Typescript</strong></summary>
```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);
```
</details>
### Цитата блога: "Ошибки программиста - это ошибки в программе"