mirror of
https://github.com/OkaeriPoland/okaeri-timings.git
synced 2026-01-18 03:28:20 +01:00
Pass backend errors to the frontend
This commit is contained in:
@@ -45,7 +45,7 @@ public class ParseController {
|
|||||||
}
|
}
|
||||||
String[] parts = line.substring(1).split(":", 2);
|
String[] parts = line.substring(1).split(":", 2);
|
||||||
if (parts.length != 2) {
|
if (parts.length != 2) {
|
||||||
throw new RuntimeException("Cannot parse metadata: '" + line + "'");
|
return ResponseEntity.badRequest().body(Map.of("error", "Cannot parse metadata: '" + line + "'"));
|
||||||
}
|
}
|
||||||
String key = parts[0].trim().toLowerCase(Locale.ROOT);
|
String key = parts[0].trim().toLowerCase(Locale.ROOT);
|
||||||
String value = parts[1].trim();
|
String value = parts[1].trim();
|
||||||
@@ -57,7 +57,7 @@ public class ParseController {
|
|||||||
if (header == null) {
|
if (header == null) {
|
||||||
String[] parts = line.split(",");
|
String[] parts = line.split(",");
|
||||||
if (parts.length < 2) {
|
if (parts.length < 2) {
|
||||||
throw new RuntimeException("Cannot parse header: '" + line + "'");
|
return ResponseEntity.badRequest().body(Map.of("error", "Cannot parse header: '" + line + "'"));
|
||||||
}
|
}
|
||||||
header = Arrays.asList(parts);
|
header = Arrays.asList(parts);
|
||||||
continue;
|
continue;
|
||||||
@@ -66,22 +66,26 @@ public class ParseController {
|
|||||||
// data
|
// data
|
||||||
String[] parts = line.split(",");
|
String[] parts = line.split(",");
|
||||||
if (parts.length != header.size()) {
|
if (parts.length != header.size()) {
|
||||||
throw new RuntimeException("Cannot parse record: '" + line + "'");
|
return ResponseEntity.badRequest().body(Map.of("error", "Cannot parse record: '" + line + "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
records.add(Arrays.stream(parts)
|
try {
|
||||||
.map(value -> {
|
records.add(Arrays.stream(parts)
|
||||||
try {
|
.map(value -> {
|
||||||
return new BigDecimal(value);
|
try {
|
||||||
} catch (Exception exception) {
|
return new BigDecimal(value);
|
||||||
throw new RuntimeException("Cannot parse value: '" + value + "' from record '" + line + "'");
|
} catch (Exception exception) {
|
||||||
}
|
throw new RuntimeException("Cannot parse value: '" + value + "' from record '" + line + "'");
|
||||||
})
|
}
|
||||||
.collect(Collectors.toList()));
|
})
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
} catch (Exception exception) {
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("error", exception.getMessage()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header == null || records.size() < 2) {
|
if (header == null || records.size() < 2) {
|
||||||
throw new RuntimeException("Invalid report");
|
return ResponseEntity.badRequest().body(Map.of("error", "Invalid report"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> stats = Map.of(
|
Map<String, Object> stats = Map.of(
|
||||||
|
|||||||
Reference in New Issue
Block a user