     new Promise (f, r) ->
         values = cache.get('tiere')
         if not values
-            #console.log "no cache"
             get_detailUrls tierheim_url
                 .then (urls) ->
                     p = []
                     for url in urls
                         p.push get_details url
                     Promise.all p
+                .catch (err)
+                    r err
                 .then (values) ->
                     cache.set('tiere', values, 60*60*24)
                     f values
+                .catch err
+                    r err
         else
-            #console.log "cache"
             f values
 
 # get a pet that was not posted yet

                fs.writeFileSync filename, JSON.stringify []
                postedPets = []
        catch err
            console.error err
            r err
        get_data().then (pets) ->
            notPostedPets = []

###

# Return all pets
app.get '/', (req, res) ->
    get_data()
        .then (pets) ->
            res.json pets
        .catch (err) ->
            console.error err
            res.status(500).json(err);

# Return a random pet
app.get '/random', (req, res) ->
    get_notPostedPet()
        .then (pet) ->
            res.json pet
        .catch (err) ->
            console.error err
            res.status(500).json(err);

server = app.listen 3000, 'localhost', ->
    host = server.address().address
