Skip to content

Commit f32ad49

Browse files
committed
linting fixes
1 parent 6bed336 commit f32ad49

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

courses/backend/node/week2/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ By the end of this session, you will be able to:
2424
- [ ] Set up multiple environments
2525
- [ ] Managing secrets
2626
- [ ] Create basic test suites
27-

courses/backend/node/week2/session-materials/phonebook/api/contacts.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ router.post("/", async (request, response) => {
1111
response.status(201).json(insertedContact); // 201 Created
1212
} catch (error) {
1313
console.error("Error inserting contact:", error); // Server side error, for developers
14-
response.status(500).json({ message: "Something went wrong on the server." }); // Client side error, for users. Avoid leaking database info.
14+
response
15+
.status(500)
16+
.json({ message: "Something went wrong on the server." }); // Client side error, for users. Avoid leaking database info.
1517
}
1618
});
1719

18-
export default router;
20+
export default router;

courses/backend/node/week2/session-materials/phonebook/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ router.use("/contacts", contactsRouter);
1515

1616
app.use("/api", router);
1717

18-
app.listen(port, () => console.log(`Server listening on port ${port}!`));
18+
app.listen(port, () => console.log(`Server listening on port ${port}!`));

courses/backend/node/week2/session-materials/phonebook/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"license": "ISC",
77
"type": "module",
88
"main": "index.js",
9-
109
"scripts": {
1110
"dev": "node --watch index.js"
1211
},

courses/backend/node/week2/session-plan.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This part of the module should explain Knex in a lot more technical detail. The
2424
- You also lose the safety of Knex's security precautions regarding SQL injetion
2525
- Using the Query Builder methods like `.select()` help us write safer, more readable DB queries that work even if we change our database type.
2626

27-
### Live coding
27+
### Live coding - Database interaction
2828

2929
Run through the [phonebook example](./session-materials/phonebook/). The functions are already written, but feel free to clear them and write them together in the session.
3030

@@ -51,7 +51,6 @@ For further reading, check the following resources:
5151
- [What is REST: a simple explanation for beginners](https://medium.com/extend/what-is-rest-a-simple-explanation-for-beginners-part-1-introduction-b4a072f8740f)
5252
- [@NoerGitKat (lots of web app clones/examples to learn from)](https://github.com/NoerGitKat)
5353

54-
5554
### Snippets API continued
5655

5756
Now we can pick up where we left the exercises last week. Help the trainees complete the remaining endpoints:
@@ -69,38 +68,43 @@ Error handling is important so we have visibility of issues that occur in applic
6968
Here are some of the most commonly used:
7069

7170
#### 2XX - Success
71+
7272
`200 OK` - The request succeeded, e.g. a webpage loads as it should.
7373
`201 Created` - A new resource was made, e.g. a new user account.
7474

7575
#### 3XX - Redirection
76+
7677
`301 Moved Permanently` - The URL has changed, e.g. redirect from oldsite.com to newsite.com.
7778
`302 Found` - A temporary redirect, e.g. redirecting Spanish visitors to the Spanish version of the website.
7879

7980
#### 4XX - Client Errors
81+
8082
`400 Bad Request` - The request was invalid, e.g. form data missing or incorrect.
8183
`401 Unauthorized` - You need to log in e.g. trying to access user features when logged out.
8284
`404 Not Found` - Nothing at that URL e.g. a missing page or resource.
8385

8486
#### 5XX - Client Errors
87+
8588
`500 Internal Server Error` - Generic server issue, e.g. something goes wrong in the backend.
8689
`503 Service Unavailable` - Server is down or busy e.g. backend API is not running.
8790

8891
Read more at [HTTP Status cheatsheet](https://devhints.io/http-status).
8992

9093
### Client vs Server
9194

92-
Server-side errors should be designed for developers. Detailed errors help debugging and ultimately fixing issues easier.
95+
Server-side errors should be designed for developers. Detailed errors help debugging and ultimately fixing issues easier.
9396
e.g. If a database table is missing, record the missing table name in your logs.
9497

95-
Client-side errors should be designed for users, including the correct HTTP status code.
98+
Client-side errors should be designed for users, including the correct HTTP status code.
9699
e.g. In the missing database table case, simply return a `500 Internal Server Error` and a useful page to the user to explain how to continue.
97100

98101
It's important to hide specific error details from the user for multiple reasons:
102+
99103
1. Security - Revealing database names and other internal details can give attackers too many clues about your system which can make your app more vulnerable to exploitation.
100104
2. Privacy - Many internal errors can include sensitive data (e.g. user IDs, personal information) that shouldn't be exposed.
101105
3. User Experience - Some technical errors would confuse most users, so stick with simple, friendly messages that can help the user continue.
102106

103-
### Live coding
107+
### Live coding - Error handling
104108

105109
Walk through [`api/contacts.js`](./session-materials/phonebook/api/contacts.js) to explain the try/catch pattern, appropriate server and client side error handling, correct usage of HTTP codes and why the knex code is insecure.
106110

0 commit comments

Comments
 (0)