logging and try catch

This commit is contained in:
Anthony Stirling
2024-06-02 11:59:43 +01:00
parent c4a620e3f5
commit eb526a5d0c
21 changed files with 125 additions and 71 deletions

View File

@@ -262,8 +262,7 @@ public class AccountWebController {
userRepository.findByUsernameIgnoreCase(
username); // Assuming findByUsername method exists
if (!user.isPresent()) {
// Handle error appropriately
return "redirect:/error"; // Example redirection in case of error
return "redirect:/error";
}
// Convert settings map to JSON string
@@ -273,8 +272,8 @@ public class AccountWebController {
settingsJson = objectMapper.writeValueAsString(user.get().getSettings());
} catch (JsonProcessingException e) {
// Handle JSON conversion error
e.printStackTrace();
return "redirect:/error"; // Example redirection in case of error
logger.error("exception", e);
return "redirect:/error";
}
String messageType = request.getParameter("messageType");

View File

@@ -15,6 +15,8 @@ import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
@@ -33,6 +35,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
@Tag(name = "General", description = "General APIs")
public class GeneralWebController {
private static final Logger logger = LoggerFactory.getLogger(GeneralWebController.class);
@GetMapping("/pipeline")
@Hidden
public String pipelineForm(Model model) {
@@ -74,7 +78,7 @@ public class GeneralWebController {
}
} catch (IOException e) {
e.printStackTrace();
logger.error("exception", e);
}
}
if (pipelineConfigsWithNames.size() == 0) {

View File

@@ -6,6 +6,8 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -26,6 +28,8 @@ import stirling.software.SPDF.model.Dependency;
@Controller
public class HomeWebController {
private static final Logger logger = LoggerFactory.getLogger(HomeWebController.class);
@GetMapping("/about")
@Hidden
public String gameForm(Model model) {
@@ -46,7 +50,7 @@ public class HomeWebController {
mapper.readValue(json, new TypeReference<Map<String, List<Dependency>>>() {});
model.addAttribute("dependencies", data.get("dependencies"));
} catch (IOException e) {
e.printStackTrace();
logger.error("exception", e);
}
return "licenses";
}