2from datetime
import datetime
as dt
3from pymongo
import MongoClient
5from dotenv
import load_dotenv, dotenv_values
6from MongoConnection
import mongo_connection
10 """Updates file info in our database with the error found in it (if it's applicable)
13 def handle(self, e, message, file_db_id):
14 """Add status_cause and error_message fields to file info
18 message (str): error message generated by python
19 file_db_id (str): file id assigned in mongodb
20 Returns: error_cause (str)
23 collection = mongo_conn.mongo_conn_snapshots()
25 collection.update_one({
"file_db_id":file_db_id},{
"$set": {
"status":
"failed",
"status_cause": error_cause,
"error_message": message,
"updated_at": dt.now()}})
30 """Gets a message error according to king of issue
37 if str(error_type) ==
"<class 'botocore.exceptions.ClientError'>":
38 return (
"S3: File does not exist. Are you sure this is the correct file")
39 elif str(error_type) ==
"<class 'botocore.exceptions.PartialCredentialsError'>":
40 return (
"S3: Partial credentials found in explicit. aws_access_key_id or aws_secret_access_key no founded")
41 elif str(e) ==
"Path invalid.":
42 return (
"S3: Input path does not exist in s3 Bucket. Are you sure this is the correct path?")
43 elif str(error_type) ==
"<class 'pymongo.errors.ServerSelectionTimeoutError'>":
44 return (
"MDB: Saving the information is taking too long. Connection refused")
45 elif str(error_type) ==
"<class 'IndexError'>":
46 return (
"MDB: No formats matches with your file")
47 elif str(e) ==
"Error in currency. Execution aborted":
48 return (
"PD: Currency not found in your file")
49 elif str(e) ==
"Validation Error. Execution aborted":
50 return (
"PD: Something was wrong. Data validation failed.")
51 elif str(error_type) ==
"<class 'NameError'>":
52 return (
"Python: There is a word not defined")
53 elif str(error_type) ==
"<class 'KeyError'>":
54 return (
"Python: There is a wrong word")
55 elif "Expecting value: line 1 column" in str(e):
56 return (
"Maybe there is a malformed format")
57 elif "cannot unpack non-iterable" in str(e):
58 return "Maybe something is wrong in headers"
69 It's launched when a not allowed file is ingested
71 def __init__(self, message="File extension is not supported. Verify if it is the correct file"):
77 It's launched when a file could not be loaded or it has a undefined encoding
79 def __init__(self, message="File couldn't be loaded. Verify that file is an accepted format"):
85 It's launched when a file contains one or more not defined currencies
87 def __init__(self, message="There are currencies not found in your file. Please check currencies"):
93 It's launched when something's wrong in the data validation procedure
95 def __init__(self, message="Something's wrong in validation step. Verify your data"):
__init__(self, message="There are currencies not found in your file. Please check currencies")
handle(self, e, message, file_db_id)
__init__(self, message="File couldn't be loaded. Verify that file is an accepted format")
__init__(self, message="File extension is not supported. Verify if it is the correct file")
__init__(self, message="Something's wrong in validation step. Verify your data")