Skip to content

Commit

Permalink
Logger issue
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbergyoni committed Apr 7, 2024
1 parent 91eb146 commit 1c93323
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 1,174 deletions.
3 changes: 2 additions & 1 deletion docs/docs/the-basics/coding-with-practica.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ Now visit our [online POSTMAN collection](https://documenter.getpostman.com/view

**Note:** The API routes authorize requests, a valid token must be provided. You may generate one yourself ([see here how](../questions-and-answers.md)), or just use the default _development_ token that we generated for you 👇. Put it inside an 'Authorization' header:

```Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2NjIwMTY5NjIsImV4cCI6MTY5MzU1Mjk2MiwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIkdpdmVuTmFtZSI6IkpvaG5ueSIsIlN1cm5hbWUiOiJSb2NrZXQiLCJFbWFpbCI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.65ACAjHy2ZE5i_uS5hyiEkOQfkqOqdj-WtBm-w23qZQ```
```Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzM4NTIyMTk5NzEsImRhdGEiOnsidXNlciI6ImpvZSIsInJvbGVzIjoiYWRtaW4ifSwiaWF0IjoxNzEyMjUyMjE5fQ.kUS7AnwtGum40biJYt0oyOH_le1KfVD2EOrs-ozclY0```

We have the ground ready 🐥. Let's code now, just remember to run the tests (or POSTMAN) once in a while to ensure nothing breaks

## The 3 layers of a component

A typical component (e.g., Microservice) contains 3 main layers. This is a known and powerful pattern that is called ["3-Tiers"](https://www.techopedia.com/definition/24649/three-tier-architecture). It's an architectural structure that strikes a great balance between simplicity and robustness. Unlike other fancy architectures (e.g. hexagonal architecture, etc), this style is more likely to keep things simple and organized. The three layers represent the physical flow of a request with no abstractions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const verifyTokenOnRequest = (
let token: string;
// A token comes in one of two forms: 'token' or 'Bearer token'
const authHeaderParts = authenticationHeader.split(' ');

if (authHeaderParts.length > 2) {
// It should have 1 or 2 parts (separated by space), the incoming string has unknown structure
return { success: false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const errorHandler = {

handleError: (errorToHandle: unknown): number => {
try {
logger.info('Handling error1');
const appError: AppError = covertUnknownToAppError(errorToHandle);
logger.error(appError.message, appError);
metricsExporter.fireMetric('error', { errorName: appError.name }); // fire any custom metric when handling error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ export function fastifyErrorMiddleware(
const standardAppError = covertUnknownToAppError(error);
standardAppError.isCatastrophic = false;
const responseToRequest = errorHandler.handleError(standardAppError);

reply.status(responseToRequest).send({});
}
6 changes: 4 additions & 2 deletions src/code-templates/libraries/error-handling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@practica/logger": "^0.0.1-alpha.4",
"@practica/logger": "^0.0.5",
"jest": "^28.1.0",
"jest-sinon": "^1.0.4",
"sinon": "^14.0.0",
"sinon": "^14.0.0"
},
"peerDependencies": {
"fastify": "4.24.3"
}
}
Empty file.
1 change: 0 additions & 1 deletion src/code-templates/libraries/jwt-token-verifier/index.ts

This file was deleted.

189 changes: 0 additions & 189 deletions src/code-templates/libraries/jwt-token-verifier/jest.config.js

This file was deleted.

This file was deleted.

35 changes: 0 additions & 35 deletions src/code-templates/libraries/jwt-token-verifier/package.json

This file was deleted.

Loading

0 comments on commit 1c93323

Please sign in to comment.