@@ -15,20 +15,20 @@ module.exports = async req => {
1515 fs . unlink ( path , ( ) => 0 ) ;
1616 }
1717
18- throw reason ;
18+ throw { code : - 1 , text : reason } ;
1919 } ) ;
2020
2121 const contentLength = Number ( req . get ( 'content-length' ) ) ;
2222
2323 // Validate header
2424 if ( isNaN ( contentLength ) ) {
25- throw 'Invalid content-length header' ;
25+ throw { code : 1 , text : 'Invalid content-length header' } ;
2626 }
2727
2828 // Compare current storage size and upload size with limit
2929 const { totalStorageLimitPerUser} = _config . server ;
3030 if ( ~ totalStorageLimitPerUser && ( await usedSpaceBy ( user . id ) ) + contentLength > totalStorageLimitPerUser ) {
31- throw `Storage limit of ${ totalStorageLimitPerUser } bytes exceed` ;
31+ throw { code : 2 , text : `Storage limit of ${ totalStorageLimitPerUser } bytes exceed` } ;
3232 }
3333
3434 // Rename files and create nodes
@@ -45,14 +45,14 @@ module.exports = async req => {
4545 const parent = fieldname . substring ( 0 , fieldname . indexOf ( '-' ) ) ;
4646 if ( ! parent ) {
4747 fs . unlinkSync ( path ) ;
48- throw 'Invalid node key' ;
48+ throw { code : 10 , text : 'Invalid node key' } ;
4949 }
5050
5151 // Check if destination exists and is a folder
5252 const destNode = await nodeModel . findOne ( { owner : user . id , id : parent } ) . exec ( ) ;
5353 if ( ! destNode || destNode . type !== 'dir' ) {
5454 fs . unlinkSync ( path ) ;
55- throw 'Invalid parent node' ;
55+ throw { code : 11 , text : 'Invalid parent node' } ;
5656 }
5757
5858 // Create and push new node
0 commit comments