I am writing some CoffeeScript code for an API, and in the error catching section of my code I placed an IF statement. Now, during the compilation process CoffeeScript is saying that the IF statement was unexpected.
# Handle Errors
app.error (err, req, res, next) ->
if err instanceof NotFound
res.send '404, not found.'
else
res.send '500, internal server error.'
app.get '/*', (req, res) ->
throw new NotFound
NotFound = (msg) ->
this.name = 'NotFound'
Error.call this, msg
Error.captureStackTrace this, arguments.callee
The error is
/home/techno/node/snaprss/application.coffee:22:5: error: unexpected if
if err instanceOf NotFound
^^
Does anyone have any ideas where the issue is within my code?
Unexpected 'INDENT' in CoffeeScript Example Code
This issue looks somehow similar.
Consider therefore checking tabs and spaces in your editor.
Another thing to watch out for parenthesis and braces:
Javascript
if (condition) {
//logic
}
should be CoffeeScript
if condition
# logic
# END if
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