From 761c12a0ba6ec5314a064a32d26b02c479f96f88 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Sun, 7 Jun 2020 01:23:31 +0200 Subject: [PATCH] Errors::Authorization. --- src/common/requests/download.cr | 3 +-- src/common/requests/errors.cr | 16 ++++++++++++---- src/common/requests/transfer.cr | 4 ++-- src/common/requests/upload.cr | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/common/requests/download.cr b/src/common/requests/download.cr index bb2ff34..ff06d74 100644 --- a/src/common/requests/download.cr +++ b/src/common/requests/download.cr @@ -12,7 +12,7 @@ class FileStorage::Request def handle(filestoraged : FileStorage::Service, event : IPC::Event::Events) user = filestoraged.get_logged_user event - raise Exception.new "unauthorized" if user.nil? + return Errors::Authorization.new @mid if user.nil? # FIXME: Maybe this should be moved to FileStorage::Service fd = event.connection.fd @@ -35,4 +35,3 @@ class FileStorage::Response end end end - diff --git a/src/common/requests/errors.cr b/src/common/requests/errors.cr index d4c3c01..5dd0ccd 100644 --- a/src/common/requests/errors.cr +++ b/src/common/requests/errors.cr @@ -7,8 +7,16 @@ class FileStorage::Errors end FileStorage.errors << GenericError + JSONIPC.request Authorization, 201 do + property mid : String + property reason : String + def initialize(@mid, @reason = "authorization") + end + end + FileStorage.errors << Authorization + # When uploading a chunk already present in the DB. - JSONIPC.request ChunkAlreadyUploaded, 201 do + JSONIPC.request ChunkAlreadyUploaded, 202 do property mid : String property reason = "Chunk already present" property filedigest : String @@ -20,7 +28,7 @@ class FileStorage::Errors FileStorage.errors << ChunkAlreadyUploaded # You upload a chunk, but you are not the owner of the file. - JSONIPC.request ChunkUploadDenied, 202 do + JSONIPC.request ChunkUploadDenied, 203 do property mid : String property reason = "This file is not yours" property filedigest : String @@ -31,7 +39,7 @@ class FileStorage::Errors FileStorage.errors << ChunkUploadDenied # When uploading a file already present in the DB. - JSONIPC.request FileExists, 203 do + JSONIPC.request FileExists, 204 do property mid : String property reason = "file already present" property filedigest : String @@ -42,7 +50,7 @@ class FileStorage::Errors FileStorage.errors << FileExists # When transfering a chunk for an inexistent file. - JSONIPC.request FileDoesNotExist, 204 do + JSONIPC.request FileDoesNotExist, 205 do property mid : String property reason = "file does not exist" property filedigest : String diff --git a/src/common/requests/transfer.cr b/src/common/requests/transfer.cr index 01c8808..b974a68 100644 --- a/src/common/requests/transfer.cr +++ b/src/common/requests/transfer.cr @@ -20,7 +20,7 @@ class FileStorage::Request def handle(filestoraged : FileStorage::Service, event : IPC::Event::Events) user = filestoraged.get_logged_user event - raise Exception.new "unauthorized" if user.nil? + return Errors::Authorization.new @mid if user.nil? # FIXME: Maybe this should be moved to FileStorage::Service fd = event.connection.fd @@ -46,7 +46,7 @@ class FileStorage::Request def handle(filestoraged : FileStorage::Service, event : IPC::Event::Events) user = filestoraged.get_logged_user event - raise Exception.new "unauthorized" if user.nil? + return Errors::Authorization.new @mid if user.nil? # FIXME: Maybe this should be moved to FileStorage::Service fd = event.connection.fd diff --git a/src/common/requests/upload.cr b/src/common/requests/upload.cr index 81c9553..1136a66 100644 --- a/src/common/requests/upload.cr +++ b/src/common/requests/upload.cr @@ -10,7 +10,7 @@ class FileStorage::Request def handle(filestoraged : FileStorage::Service, event : IPC::Event::Events) user = filestoraged.get_logged_user event - raise Exception.new "unauthorized" if user.nil? + return Errors::Authorization.new @mid if user.nil? # FIXME: Maybe this should be moved to FileStorage::Service fd = event.connection.fd