Skip to content

Commit 0eee7b6

Browse files
committed
tweaks part 3
1 parent 7368d03 commit 0eee7b6

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/content/3/en/part3c.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ app.get('/api/notes/:id', (request, response) => {
691691

692692
If no matching object is found in the database, the value of _note_ will be _null_ and the _else_ block is executed. This results in a response with the status code <i>404 not found</i>. If a promise returned by the <em>findById</em> method is rejected, the response will have the status code <i>500 internal server error</i>. The console displays more detailed information about the error.
693693

694-
On top of the non-existing note, there's one more error situation that needs to be handled. In this situation, we are trying to fetch a note with the wrong kind of _id_, meaning an _id_ that doesn't match the mongo identifier format.
694+
On top of the non-existing note, there's one more error situation that needs to be handled. In this situation, we are trying to fetch a note with the wrong kind of _id_, meaning an _id_ that doesn't match the Mongo identifier format.
695695

696696
If we make the following request, we will get the error message shown below:
697697

@@ -785,13 +785,13 @@ const errorHandler = (error, request, response, next) => {
785785
next(error)
786786
}
787787

788-
// this has to be the last loaded middleware.
788+
// this has to be the last loaded middleware, also all the routes should be registered before this!
789789
app.use(errorHandler)
790790
```
791791

792792
The error handler checks if the error is a <i>CastError</i> exception, in which case we know that the error was caused by an invalid object id for Mongo. In this situation, the error handler will send a response to the browser with the response object passed as a parameter. In all other error situations, the middleware passes the error forward to the default Express error handler.
793793

794-
Note that the error-handling middleware has to be the last loaded middleware!
794+
Note that the error-handling middleware has to be the last loaded middleware, also all the routes should be registered before the error-handler!
795795

796796
### The order of middleware loading
797797

@@ -875,7 +875,7 @@ app.delete('/api/notes/:id', (request, response, next) => {
875875
})
876876
```
877877

878-
In both of the "successful" cases of deleting a resource, the backend responds with the status code <i>204 no content</i>. The two different cases are deleting a note that exists, and deleting a note that does not exist in the database. The _result_ callback parameter could be used for checking if a resource was actually deleted, and we could use that information for returning different status codes for the two cases if we deemed it necessary. Any exception that occurs is passed onto the error handler.
878+
In both of the "successful" cases of deleting a resource, the backend responds with the status code <i>204 no content</i>. The two different cases are deleting a note that exists, and deleting a note that does not exist in the database. The _result_ callback parameter could be used for checking if a resource was actually deleted, and we could use that information for returning different status codes for the two cases if we deem it necessary. Any exception that occurs is passed onto the error handler.
879879

880880
The toggling of the importance of a note can be easily accomplished with the [findByIdAndUpdate](https://mongoosejs.com/docs/api/model.html#model_Model-findByIdAndUpdate) method.
881881

src/content/3/fi/osa3c.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,13 +778,13 @@ const errorHandler = (error, request, response, next) => {
778778
next(error)
779779
}
780780

781-
// tämä tulee kaikkien muiden middlewarejen rekisteröinnin jälkeen!
781+
// tämä tulee kaikkien muiden middlewarejen ja routejen rekisteröinnin jälkeen!
782782
app.use(errorHandler)
783783
```
784784

785785
Virheenkäsittelijä tarkastaa, onko kyse <i>CastError</i>-poikkeuksesta eli virheellisestä olio-id:stä. Jos on, käsittelijä lähettää pyynnön tehneelle selaimelle vastauksen käsittelijän parametrina olevan response-olion avulla. Muussa tapauksessa se siirtää funktiolla <em>next</em> virheen käsittelyn Expressin oletusarvoisen virheidenkäsittelijän hoidettavaksi.
786786

787-
Huomaa, että virheidenkäsittelijämiddleware tulee rekisteröidä muiden middlewarejen rekisteröinnin jälkeen.
787+
Huomaa, että virheidenkäsittelijämiddleware tulee rekisteröidä muiden middlewarejen sekä routejen rekisteröinnin jälkeen.
788788

789789
### Middlewarejen käyttöönottojärjestys
790790

0 commit comments

Comments
 (0)