Skip to content

Commit

Permalink
Used more standard errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jun 1, 2017
1 parent ec514e0 commit 155035c
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 16 deletions.
3 changes: 3 additions & 0 deletions lib/Errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export declare const Errors: {
UserNotFound: Error;
XMLNotFound: Error;
ExpectedAFileResourceType: Error;
NoMimeTypeForAFolder: Error;
NoSizeForAFolder: Error;
IllegalArguments: Error;
None: any;
};
export default Errors;
3 changes: 3 additions & 0 deletions lib/Errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ exports.Errors = {
UserNotFound: new Error('User not found'),
XMLNotFound: new Error('Can\'t find the XML element.'),
ExpectedAFileResourceType: new Error('Expected a file resource type.'),
NoMimeTypeForAFolder: new Error('Cannot get the mime type of a folder type resource'),
NoSizeForAFolder: new Error('Cannot get the size of a folder type resource'),
IllegalArguments: new Error('Illegal arguments'),
None: null
};
exports.default = exports.Errors;
4 changes: 2 additions & 2 deletions lib/resource/physical/PhysicalFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ var PhysicalFolder = (function (_super) {
callback(Errors_1.Errors.InvalidOperation, null);
};
PhysicalFolder.prototype.mimeType = function (targetSource, callback) {
callback(new Error('Cannot get the mime type of a folder type resource'), null);
callback(Errors_1.Errors.NoMimeTypeForAFolder, null);
};
PhysicalFolder.prototype.size = function (targetSource, callback) {
callback(new Error('Cannot get the size of a folder type resource'), null);
callback(Errors_1.Errors.NoSizeForAFolder, null);
};
PhysicalFolder.prototype.addChild = function (resource, callback) {
var _this = this;
Expand Down
4 changes: 2 additions & 2 deletions lib/resource/virtual/VirtualFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ var VirtualFolder = (function (_super) {
callback(Errors_1.Errors.InvalidOperation, null);
};
VirtualFolder.prototype.mimeType = function (targetSource, callback) {
callback(new Error('Cannot get the mime type of a folder type resource'), null);
callback(Errors_1.Errors.NoMimeTypeForAFolder, null);
};
VirtualFolder.prototype.size = function (targetSource, callback) {
callback(new Error('Cannot get the size of a folder type resource'), null);
callback(Errors_1.Errors.NoSizeForAFolder, null);
};
VirtualFolder.prototype.addChild = function (resource, callback) {
var _this = this;
Expand Down
4 changes: 2 additions & 2 deletions lib/resource/virtualStored/VirtualStoredFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ var VirtualStoredFolder = (function (_super) {
callback(Errors_1.Errors.InvalidOperation, null);
};
VirtualStoredFolder.prototype.mimeType = function (targetSource, callback) {
callback(new Error('Cannot get the mime type of a folder type resource'), null);
callback(Errors_1.Errors.NoMimeTypeForAFolder, null);
};
VirtualStoredFolder.prototype.size = function (targetSource, callback) {
callback(new Error('Cannot get the size of a folder type resource'), null);
callback(Errors_1.Errors.NoSizeForAFolder, null);
};
VirtualStoredFolder.prototype.addChild = function (resource, callback) {
var _this = this;
Expand Down
4 changes: 2 additions & 2 deletions lib/server/WebDAVServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ var WebDAVServer = (function () {
if (callback instanceof Function)
_callback = callback;
else
throw new Error('Illegal arguments');
throw Errors_1.Errors.IllegalArguments;
}
}
else if (port && port.constructor === Function) {
_port = this.options.port;
_callback = port;
if (callback)
throw new Error('Illegal arguments');
throw Errors_1.Errors.IllegalArguments;
}
if (!this.server) {
this.server = http.createServer(function (req, res) {
Expand Down
3 changes: 3 additions & 0 deletions src/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const Errors = {
UserNotFound: new Error('User not found'),
XMLNotFound: new Error('Can\'t find the XML element.'),
ExpectedAFileResourceType: new Error('Expected a file resource type.'),
NoMimeTypeForAFolder: new Error('Cannot get the mime type of a folder type resource'),
NoSizeForAFolder: new Error('Cannot get the size of a folder type resource'),
IllegalArguments: new Error('Illegal arguments'),

None: null
};
Expand Down
4 changes: 2 additions & 2 deletions src/resource/physical/PhysicalFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ export class PhysicalFolder extends PhysicalResource
}
mimeType(targetSource : boolean, callback : ReturnCallback<string>)
{
callback(new Error('Cannot get the mime type of a folder type resource'), null);
callback(Errors.NoMimeTypeForAFolder, null);
}
size(targetSource : boolean, callback : ReturnCallback<number>)
{
callback(new Error('Cannot get the size of a folder type resource'), null);
callback(Errors.NoSizeForAFolder, null);
}

// ****************************** Children ****************************** //
Expand Down
4 changes: 2 additions & 2 deletions src/resource/virtual/VirtualFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class VirtualFolder extends VirtualResource
}
mimeType(targetSource : boolean, callback : ReturnCallback<string>)
{
callback(new Error('Cannot get the mime type of a folder type resource'), null);
callback(Errors.NoMimeTypeForAFolder, null);
}
size(targetSource : boolean, callback : ReturnCallback<number>)
{
callback(new Error('Cannot get the size of a folder type resource'), null);
callback(Errors.NoSizeForAFolder, null);
}

// ****************************** Children ****************************** //
Expand Down
4 changes: 2 additions & 2 deletions src/resource/virtualStored/VirtualStoredFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class VirtualStoredFolder extends VirtualStoredResource
}
mimeType(targetSource : boolean, callback : ReturnCallback<string>)
{
callback(new Error('Cannot get the mime type of a folder type resource'), null);
callback(Errors.NoMimeTypeForAFolder, null);
}
size(targetSource : boolean, callback : ReturnCallback<number>)
{
callback(new Error('Cannot get the size of a folder type resource'), null);
callback(Errors.NoSizeForAFolder, null);
}

// ****************************** Children ****************************** //
Expand Down
4 changes: 2 additions & 2 deletions src/server/WebDAVServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ export class WebDAVServer
if(callback instanceof Function)
_callback = callback;
else
throw new Error('Illegal arguments');
throw Errors.IllegalArguments;
}
}
else if(port && port.constructor === Function)
{
_port = this.options.port;
_callback = port as WebDAVServerStartCallback;
if(callback)
throw new Error('Illegal arguments');
throw Errors.IllegalArguments;
}

if(!this.server)
Expand Down

0 comments on commit 155035c

Please sign in to comment.