Errata: Listing 5.2


Errata: Listing 5.2 Switch cases can have multiple values

There should be a “+=” in the line

Otherwise, the initial value of errorString (“The request failed with the error:”) is not used.
The same line of code is deleted in Listing 5.3, but it shows the line with a +=.

Corrected code:

import Cocoa

var statusCode: Int = 404
var errorString: String = “The request failed with the error:”

switch statusCode {
case 400, 401, 403, 404:
errorString += " There was something wrong with the request.“
errorString += " Please review the request and try again.”


I agree with twanco. As part of the correction, the error text in the fifth paragraph after Listing 5.2 will also need to be updated.



If nothing is matched and only the default is selected the string built with += doesn’t make much sense


I think that econ5000 is correct.

In the first case, there was a request error (400, 401, 403, 404) The command request is ok, but the server appoint to http error. In the second error, the command is wrong and the user must review the request.