Is there a way to convert an error of type NSError in swift to a string?
For example for something like this:
do {
try response.status(.OK).send(fileName: "html/index.html")
} catch {
response.status(.FAIL).send(error.CONVERT_TO_STRING)
}
.send() expects a string by default.
If your error is of type NSError
, you can use error.localizedDescription
to get the string.
error.localizedDescription
doesn't always contain all the information you need. In that instance you do have the option of converting the whole object to a string...
let description = "\(error)"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With