1818 VERSION = "dev"
1919
2020
21+ class DBTCloudException (Exception ):
22+ pass
23+
24+
25+ class DBTCloudParamsException (Exception ):
26+ pass
27+
28+
2129class DBTCloud :
2230 """A minimalistic API client for fetching dbt Cloud data."""
2331
@@ -56,10 +64,10 @@ def _clear_env_var_cache(self, job_definition_id: Optional[int]) -> None:
5664 def _check_for_creds (self ):
5765 """Confirm the presence of credentials"""
5866 if not self ._api_key :
59- raise Exception ("An API key is required to get dbt Cloud jobs." )
67+ raise DBTCloudParamsException ("An API key is required to get dbt Cloud jobs." )
6068
6169 if not self .account_id :
62- raise Exception ("An account_id is required to get dbt Cloud jobs." )
70+ raise DBTCloudParamsException ("An account_id is required to get dbt Cloud jobs." )
6371
6472 def build_mapping_job_identifier_job_id (
6573 self , cloud_jobs : Optional [List [JobDefinition ]] = None
@@ -89,6 +97,7 @@ def update_job(self, job: JobDefinition) -> JobDefinition:
8997
9098 if response .status_code >= 400 :
9199 logger .error (response .json ())
100+ raise DBTCloudException (f"Error updating job { job .name } " )
92101 else :
93102 logger .success ("Job updated successfully." )
94103
@@ -108,6 +117,7 @@ def create_job(self, job: JobDefinition) -> Optional[JobDefinition]:
108117
109118 if response .status_code >= 400 :
110119 logger .error (response .json ())
120+ raise DBTCloudException (f"Error creating job { job .name } " )
111121 return None
112122 else :
113123 logger .success ("Job created successfully." )
@@ -127,6 +137,7 @@ def delete_job(self, job: JobDefinition) -> None:
127137
128138 if response .status_code >= 400 :
129139 logger .error (response .json ())
140+ raise DBTCloudException (f"Error deleting job { job .name } " )
130141 else :
131142 logger .success ("Job deleted successfully." )
132143
@@ -142,7 +153,7 @@ def get_job(self, job_id: int) -> Optional[JobDefinition]:
142153 )
143154 if response .status_code > 200 :
144155 logger .error (f"Issue getting the job { job_id } " )
145- return None
156+ raise DBTCloudException ( f"Error getting the job { job_id } " )
146157 return JobDefinition (** response .json ()["data" ])
147158
148159 def get_job_missing_fields (self , job_id : int ) -> Optional [JobMissingFields ]:
@@ -157,7 +168,7 @@ def get_job_missing_fields(self, job_id: int) -> Optional[JobMissingFields]:
157168 )
158169 if response .status_code > 200 :
159170 logger .error (f"Issue getting the job { job_id } " )
160- return None
171+ raise DBTCloudException ( f"Error getting the job { job_id } " )
161172 return JobMissingFields (** response .json ()["data" ])
162173
163174 def get_jobs (
@@ -285,6 +296,7 @@ def create_env_var(
285296
286297 if response .status_code >= 400 :
287298 logger .error (response .json ())
299+ raise DBTCloudException (f"Error creating the env var { env_var .name } " )
288300
289301 # If the new environment variables has a job_definition_id, then clear the EnvVar cache.
290302 self ._clear_env_var_cache (job_definition_id = env_var .job_definition_id )
@@ -329,6 +341,7 @@ def update_env_var(
329341
330342 if response .status_code >= 400 :
331343 logger .error (response .json ())
344+ raise DBTCloudException (f"Error updating the env var { custom_env_var .name } " )
332345
333346 self ._clear_env_var_cache (job_definition_id = payload .job_definition_id )
334347
@@ -348,6 +361,7 @@ def delete_env_var(self, project_id: int, env_var_id: int) -> None:
348361
349362 if response .status_code >= 400 :
350363 logger .error (response .json ())
364+ raise DBTCloudException (f"Error deleting the env var { env_var_id } " )
351365
352366 logger .success ("Env Var Job Overwrite deleted successfully." )
353367
0 commit comments