Browse Source

error handling in main

master
Walid Bekkal 2 years ago
parent
commit
7121ba3630
  1. 25
      srcs/webserv.cpp

25
srcs/webserv.cpp

@ -6,23 +6,26 @@ int Master::_min_fd = INT_MAX;
int Master::_amount = 0; int Master::_amount = 0;
int main(int ac, char **av) { int main(int ac, char **av) {
if (ac != 2) { try {
cout << "Usage:\n./webserv CONF.json\n"; if (ac > 2)
return EXIT_SUCCESS; throw std::runtime_error("Too many arguments");
} std::string config_file = "default.json";
if (ac == 2)
std::ifstream file(av[1]); config_file = av[1];
if (!file.good()) { std::ifstream file(config_file);
cout << "Error: " << av[1] << " is not a valid file\n"; if (!file.good())
return EXIT_FAILURE; throw std::runtime_error("File not found");
}
cout << "Parsing configuration file from JSON conf file.\n"; cout << "Parsing configuration file from JSON conf file.\n";
cout << "You must be sure the syntax is correct\n"; cout << "You must be sure the syntax is correct\n";
JSONParser parser(av[1]); JSONParser parser(config_file);
JSONNode *conf = parser.parse(); JSONNode *conf = parser.parse();
cout << "Initialization of server...\n"; cout << "Initialization of server...\n";
Env env(conf); Env env(conf);
while (1) while (1)
env.cycle(); env.cycle();
}
catch(const std::exception& e) {
std::cerr << e.what() << '\n';
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

Loading…
Cancel
Save