Skip to content

Commit a5f2489

Browse files
committed
part 4 update
1 parent 66d046a commit a5f2489

File tree

8 files changed

+3212
-33
lines changed

8 files changed

+3212
-33
lines changed

src/components/InfoBanner.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React from 'react';
22

33
const InfoBanner = ({ visible, onHide }) => {
4-
if (!visible) return null;
4+
const relevant = window.location.href.includes('osa4') || window.location.href.includes('en/part4')
5+
6+
if (!relevant || !visible) return null;
57

68
const style = {
79
padding: 10,
@@ -46,21 +48,9 @@ const InfoBanner = ({ visible, onHide }) => {
4648
<div style={style}>
4749
<div style={textStyle}>
4850
<p>
49-
There are some changes in part 9. The <i>Patientor</i> example app
50-
structure has been refactored to a less complex form to make it easier
51-
to concentrate on learning TypeScript.
51+
The testing library used in part 4 was changed 13th February 2024 from Jest to Node:test.
52+
If you have started with Jest, you may continue. The relevant material is still available, see the "Legacy: testing with Jest"
5253
</p>
53-
<div style={{ marginTop: 10 }}>
54-
If you are just working with the old Patientor, no worries, the old
55-
material shall stay online for a couple of weeks.
56-
</div>
57-
58-
<div style={{ marginTop: 10 }}>
59-
<i>
60-
If you have already completed the part 9, this change has absolutely
61-
no effect on your progress.
62-
</i>
63-
</div>
6454
</div>
6555
<div style={buttonDiv}>
6656
<button style={buttonStyle} onClick={onHide}>

src/components/layout.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Footer from './Footer/Footer';
1010
import PropTypes from 'prop-types';
1111
import SkipToContent from './SkipToContent/SkipToContent';
1212

13-
const BANNER_TO_KEY = 'part_9_changes';
13+
const BANNER_TO_KEY = 'part_4_changes';
1414

1515
const Layout = props => {
1616
const { i18n } = useTranslation();
@@ -38,7 +38,7 @@ const Layout = props => {
3838

3939
<Header lang={siteLanguage} />
4040

41-
<InfoBanner onHide={() => hideNote()} visible={false} />
41+
<InfoBanner onHide={() => hideNote()} visible={visible} />
4242

4343
<main id="main-content">{children}</main>
4444

src/content/4/en/part4d.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,14 @@ If the token is missing or it is invalid, the exception <i>JsonWebTokenError</i>
220220

221221
```js
222222
const errorHandler = (error, request, response, next) => {
223-
logger.error(error.message)
224-
225223
if (error.name === 'CastError') {
226224
return response.status(400).send({ error: 'malformatted id' })
227225
} else if (error.name === 'ValidationError') {
228226
return response.status(400).json({ error: error.message })
227+
} else if (error.name === 'MongoServerError' && error.message.includes('E11000 duplicate key error')) {
228+
return response.status(400).json({ error: 'expected `username` to be unique' })
229229
} else if (error.name === 'JsonWebTokenError') { // highlight-line
230-
return response.status(401).json({ error: error.message }) // highlight-line
230+
return response.status(400).json({ error: 'token missing or invalid' }) // highlight-line
231231
}
232232

233233
next(error)
@@ -252,13 +252,13 @@ A new note can now be created using Postman if the <i>authorization</i> header i
252252

253253
Using Postman this looks as follows:
254254

255-
![postman adding bearer token](../../images/4/20ea.png)
255+
![postman adding bearer token](../../images/4/20new.png)
256256

257257
and with Visual Studio Code REST client
258258

259-
![vscode adding bearer token example](../../images/4/21eb.png)
259+
![vscode adding bearer token example](../../images/4/21new.png)
260260

261-
Current application code can be found on [Github](https://github.com/fullstack-hy2020/part3-notes-backend/tree/part4-9), branch <i>part4-9</i>.
261+
Current application code can be found on [GitHub](https://github.com/fullstack-hy2020/part3-notes-backend/tree/part4-9), branch <i>part4-9</i>.
262262

263263
If the application has multiple interfaces requiring identification, JWT's validation should be separated into its own middleware. An existing library like [express-jwt](https://www.npmjs.com/package/express-jwt) could also be used.
264264

@@ -315,6 +315,10 @@ const errorHandler = (error, request, response, next) => {
315315
return response.status(400).send({ error: 'malformatted id' })
316316
} else if (error.name === 'ValidationError') {
317317
return response.status(400).json({ error: error.message })
318+
} else if (error.name === 'MongoServerError' && error.message.includes('E11000 duplicate key error')) {
319+
return response.status(400).json({
320+
error: 'expected `username` to be unique'
321+
})
318322
} else if (error.name === 'JsonWebTokenError') {
319323
return response.status(401).json({
320324
error: 'invalid token'

0 commit comments

Comments
 (0)