-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from outpostHQ/enhance/gitserver
Enhance/gitserver
- Loading branch information
Showing
6 changed files
with
193 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from dataclasses import dataclass | ||
from functools import wraps | ||
from typing import Optional | ||
|
||
import requests | ||
from outpostkit.repository.lfs.logger import create_lfs_logger | ||
|
||
_log = create_lfs_logger(__name__) | ||
|
||
|
||
class LFSException(Exception): | ||
def __init__( | ||
self, code: int, message: str, doc_url: Optional[str] = None, *args: object | ||
) -> None: | ||
self.message = message | ||
self.code = code | ||
self.doc_url = doc_url | ||
super().__init__(*args) | ||
|
||
|
||
@dataclass | ||
class ProxyLFSException: | ||
message: str | ||
code: int | ||
doc_url: Optional[str] = None | ||
|
||
|
||
def handle_request_errors(function): | ||
@wraps(function) | ||
def wrapper(): | ||
try: | ||
return function() | ||
except requests.exceptions.HTTPError as errh: | ||
_log.error(errh) | ||
return ProxyLFSException( | ||
code=errh.response.status_code, message=errh.strerror | ||
) | ||
except requests.exceptions.ConnectionError as errc: | ||
_log.error(errc) | ||
return ProxyLFSException( | ||
code=500, message=f"Connection Error: {errc.strerror}" | ||
) | ||
except requests.exceptions.Timeout as errt: | ||
_log.error(errt) | ||
return ProxyLFSException( | ||
code=500, message=f"Connection Timed Out: {errt.strerror}" | ||
) | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters