Refactor error handling in attachment operations: standardize error messages and remove logging statements

This commit is contained in:
netkas 2025-06-06 01:06:07 -04:00
parent 04b4714da6
commit 3df51cf4b1
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
3 changed files with 1 additions and 5 deletions

View file

@ -62,7 +62,6 @@
}
catch(DatabaseOperationException $e)
{
Logger::log()->error(sprintf('Failed to delete attachment %s: %s', $attachmentUuid, $e->getMessage()), $e);
throw new RequestException('Internal Server Error: Unable to create operator', 500, $e);
}

View file

@ -65,7 +65,7 @@
}
catch(Throwable $e)
{
throw new RequestException('Error retrieving attachment: ' . $e->getMessage(), 500, $e);
throw new RequestException('Internal server error while retrieving attachment', 500, $e);
}
$fileLocation = Configuration::getServerConfiguration()->getStoragePath() . DIRECTORY_SEPARATOR . $attachment->getUuid();

View file

@ -4,7 +4,6 @@
use FederationServer\Classes\Configuration;
use FederationServer\Classes\Enums\AuditLogType;
use FederationServer\Classes\Logger;
use FederationServer\Classes\Managers\AuditLogManager;
use FederationServer\Classes\Managers\EvidenceManager;
use FederationServer\Classes\Managers\FileAttachmentManager;
@ -153,14 +152,12 @@
{
// If database insertion fails, remove the file to maintain consistency
@unlink($destinationPath);
Logger::log()->error(sprintf('Failed to record file upload for evidence %s: %s', $evidenceUuid, $e->getMessage()), $e);
throw new RequestException('Internal Server Error: Unable to create file attachment record', 500, $e);
}
catch (Throwable $e)
{
// Handle any other unexpected errors
@unlink($destinationPath);
Logger::log()->error(sprintf('Unexpected error during file upload for evidence %s: %s', $evidenceUuid, $e->getMessage()));
throw new RequestException('Internal Server Error', 500, $e);
}
finally