Errata: Listing 5.2


#1

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:

[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.“
fallthrough
default:
errorString += " Please review the request and try again.”
}[/code]


#2

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.

Will


#3

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


#4

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.