You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: courses/backend/node/week2/session-plan.md
+9-5Lines changed: 9 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ This part of the module should explain Knex in a lot more technical detail. The
24
24
- You also lose the safety of Knex's security precautions regarding SQL injetion
25
25
- Using the Query Builder methods like `.select()` help us write safer, more readable DB queries that work even if we change our database type.
26
26
27
-
### Live coding
27
+
### Live coding - Database interaction
28
28
29
29
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.
30
30
@@ -51,7 +51,6 @@ For further reading, check the following resources:
51
51
-[What is REST: a simple explanation for beginners](https://medium.com/extend/what-is-rest-a-simple-explanation-for-beginners-part-1-introduction-b4a072f8740f)
52
52
-[@NoerGitKat (lots of web app clones/examples to learn from)](https://github.com/NoerGitKat)
53
53
54
-
55
54
### Snippets API continued
56
55
57
56
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
69
68
Here are some of the most commonly used:
70
69
71
70
#### 2XX - Success
71
+
72
72
`200 OK` - The request succeeded, e.g. a webpage loads as it should.
73
73
`201 Created` - A new resource was made, e.g. a new user account.
74
74
75
75
#### 3XX - Redirection
76
+
76
77
`301 Moved Permanently` - The URL has changed, e.g. redirect from oldsite.com to newsite.com.
77
78
`302 Found` - A temporary redirect, e.g. redirecting Spanish visitors to the Spanish version of the website.
78
79
79
80
#### 4XX - Client Errors
81
+
80
82
`400 Bad Request` - The request was invalid, e.g. form data missing or incorrect.
81
83
`401 Unauthorized` - You need to log in e.g. trying to access user features when logged out.
82
84
`404 Not Found` - Nothing at that URL e.g. a missing page or resource.
83
85
84
86
#### 5XX - Client Errors
87
+
85
88
`500 Internal Server Error` - Generic server issue, e.g. something goes wrong in the backend.
86
89
`503 Service Unavailable` - Server is down or busy e.g. backend API is not running.
87
90
88
91
Read more at [HTTP Status cheatsheet](https://devhints.io/http-status).
89
92
90
93
### Client vs Server
91
94
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.
93
96
e.g. If a database table is missing, record the missing table name in your logs.
94
97
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.
96
99
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.
97
100
98
101
It's important to hide specific error details from the user for multiple reasons:
102
+
99
103
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.
100
104
2. Privacy - Many internal errors can include sensitive data (e.g. user IDs, personal information) that shouldn't be exposed.
101
105
3. User Experience - Some technical errors would confuse most users, so stick with simple, friendly messages that can help the user continue.
102
106
103
-
### Live coding
107
+
### Live coding - Error handling
104
108
105
109
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.
0 commit comments