         binary       : file.binary
 
     Photo.create photo, (err, photo) ->
-        return next err if err
+        if err?
+            log.error "Error creating photo from file #{file.id}"
+            log.raw err
+            return next err
 
         if photo.binary?.thumb? and photo.binary.screen?
             res.status(201).send photo

            # Add content thumb or screen if necessary
            rawFile = "/tmp/#{photo.id}"
            download res, file, rawFile, (err) ->
                if err
                    fs.unlink rawfile ->
                        return next err
                else
                    if not photo.binary.thumb?
                        thumbHelpers.resize rawFile, photo, 'thumb', (err) ->
                            if err
                                fs.unlink rawfile ->
                                    return next err
                            else
                                thumbHelpers.resize rawFile, photo, 'screen', (err) ->
                                    fs.unlink rawFile, ->
                                        res.status(201).send photo
                    else if not photo.binary.screen?
                        thumbHelpers.resize rawFile, photo, 'screen', (err) ->
                            fs.unlink rawFile, ->
                                res.status(201).send photo

async = require 'async'
fs = require 'fs'
thumbHelpers = require '../helpers/thumb'
log = require('printit')
    date: true
    prefix: "file"

onThumbCreation = require('../helpers/initializer').onThumbCreation
fileByPage = 5 * 12
