Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added exception handler for expired lighthouse token. #1884

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contract_api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ class InvalidFilePath(CustomException):
def __init__(self, file_path=None):
super().__init__(error_details=f"File not found in path {file_path}")

class LighthouseInternalException(CustomException):
error_message = "LIGHTHOUSE_INTERNAL_SERVER_ERROR"

def __init__(self):
super().__init__({})
7 changes: 6 additions & 1 deletion contract_api/infrastructure/storage_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from common.exceptions import BadRequestException
from contract_api.config import IPFS_URL
from contract_api.exceptions import LighthouseInternalException
from common.logger import get_logger

import ipfshttpclient
Expand Down Expand Up @@ -82,7 +83,11 @@ def __upload_to_provider(self, file_path: str, provider_type: StorageProviderTyp
if provider_type == StorageProviderType.IPFS:
metadata_hash = self.__ipfs_util.write_file_in_ipfs(file_path)
elif provider_type == StorageProviderType.FILECOIN:
metadata_hash = self.__lighthouse_client.upload(file_path)["data"]["Hash"]
try:
metadata_hash = self.__lighthouse_client.upload(file_path)["data"]["Hash"]
except Exception as e:
raise LighthouseInternalException(
"Internal Lighthouse server error. Please check your Lighthouse token.")
else:
raise ValueError(f"Unsupported provider type: {provider_type}")
return self.hash_to_uri(metadata_hash, provider_type)
Expand Down
9 changes: 8 additions & 1 deletion registry/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,16 @@ def __init__(self):
http_code=HTTPStatus.FORBIDDEN
)

class LighthouseInternalException(CustomException):
error_message = "LIGHTHOUSE_INTERNAL_SERVER_ERROR"

def __init__(self):
super().__init__({})

EXCEPTIONS = (BadRequestException, OrganizationNotFoundException, InvalidOriginException, MethodNotImplemented,
InvalidOrganizationStateException, InvalidMetadataException, InvalidServiceStateException,
ServiceProtoNotFoundException, OrganizationNotPublishedException, ForbiddenException,
ServiceNotFoundException, ServiceGroupNotFoundException, EnvironmentNotFoundException,
InvalidSlackUserException, InvalidSlackChannelException, InvalidSlackSignatureException,
InvalidFileTypeException, FileNotFoundException, OperationNotAllowed, InvalidOrganizationType)
InvalidFileTypeException, FileNotFoundException, OperationNotAllowed, InvalidOrganizationType,
LighthouseInternalException)
6 changes: 5 additions & 1 deletion registry/infrastructure/storage_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from common.exceptions import BadRequestException
from registry.config import IPFS_URL
from registry.exceptions import LighthouseInternalException
from common.logger import get_logger

import ipfshttpclient
Expand Down Expand Up @@ -77,7 +78,10 @@ def __upload_to_provider(self, file_path: str, provider_type: StorageProviderTyp
if provider_type == StorageProviderType.IPFS:
metadata_hash = self.__ipfs_util.write_file_in_ipfs(file_path)
elif provider_type == StorageProviderType.FILECOIN:
metadata_hash = self.__lighthouse_client.upload(file_path)["data"]["Hash"]
try:
metadata_hash = self.__lighthouse_client.upload(file_path)["data"]["Hash"]
except Exception as e:
raise LighthouseInternalException("Internal Lighthouse server error. Please check your Lighthouse token.")
else:
raise ValueError(f"Unsupported provider type: {provider_type}")
return self.hash_to_uri(metadata_hash, provider_type)
Expand Down