Skip to content

Commit

Permalink
[backend] Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 committed Dec 20, 2024
1 parent 4b85cf0 commit 8cc6f42
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 27 deletions.

This file was deleted.

49 changes: 49 additions & 0 deletions openbas-api/src/main/java/io/openbas/rest/log/LogApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.openbas.rest.log;

import io.openbas.rest.helper.RestBehavior;
import io.openbas.rest.log.form.LogDetailsInput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LogApi extends RestBehavior {

public static final Logger logger = LoggerFactory.getLogger(LogApi.class);

@PostMapping("/api/logs")
public void logDetails(@RequestBody LogDetailsInput logDetailsInput) {
switch (logDetailsInput.getLevel()) {
case "WARN":
logger.warn(

Check warning on line 20 in openbas-api/src/main/java/io/openbas/rest/log/LogApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/log/LogApi.java#L20

Added line #L20 was not covered by tests
"Message warn received: {} stacktrace: {} at {}",
logDetailsInput.getMessage(),
logDetailsInput.getStack(),
logDetailsInput.getTimestamp());
break;

Check warning on line 25 in openbas-api/src/main/java/io/openbas/rest/log/LogApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/log/LogApi.java#L22-L25

Added lines #L22 - L25 were not covered by tests
case "INFO":
logger.info(

Check warning on line 27 in openbas-api/src/main/java/io/openbas/rest/log/LogApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/log/LogApi.java#L27

Added line #L27 was not covered by tests
"Message info received: {} stacktrace: {} at {}",
logDetailsInput.getMessage(),
logDetailsInput.getStack(),
logDetailsInput.getTimestamp());
break;

Check warning on line 32 in openbas-api/src/main/java/io/openbas/rest/log/LogApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/log/LogApi.java#L29-L32

Added lines #L29 - L32 were not covered by tests
case "DEBUG":
logger.debug(

Check warning on line 34 in openbas-api/src/main/java/io/openbas/rest/log/LogApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/log/LogApi.java#L34

Added line #L34 was not covered by tests
"Message debug received: {} stacktrace: {} at {}",
logDetailsInput.getMessage(),
logDetailsInput.getStack(),
logDetailsInput.getTimestamp());
break;

Check warning on line 39 in openbas-api/src/main/java/io/openbas/rest/log/LogApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/log/LogApi.java#L36-L39

Added lines #L36 - L39 were not covered by tests
default:
logger.error(

Check warning on line 41 in openbas-api/src/main/java/io/openbas/rest/log/LogApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/log/LogApi.java#L41

Added line #L41 was not covered by tests
"Message error received: {} stacktrace: {} at {}",
logDetailsInput.getMessage(),
logDetailsInput.getStack(),
logDetailsInput.getTimestamp());

Check warning on line 45 in openbas-api/src/main/java/io/openbas/rest/log/LogApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/log/LogApi.java#L43-L45

Added lines #L43 - L45 were not covered by tests
break;
}
}

Check warning on line 48 in openbas-api/src/main/java/io/openbas/rest/log/LogApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/log/LogApi.java#L48

Added line #L48 was not covered by tests
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.openbas.rest.collector_frontend_error.form;
package io.openbas.rest.log.form;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ErrorDetailsInput {
public class LogDetailsInput {

Check warning on line 8 in openbas-api/src/main/java/io/openbas/rest/log/form/LogDetailsInput.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/log/form/LogDetailsInput.java#L8

Added line #L8 was not covered by tests

private String message;
private String stack;
private String timestamp;
private String level;
}
3 changes: 2 additions & 1 deletion openbas-front/src/utils/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ export const sendErrorToBackend = async (error: Error, stack: ErrorInfo) => {
message: error.message,
stack: stack.componentStack,
timestamp: new Date().toISOString(),
level: 'ERROR',
};
simplePostCall('/api/logs/frontend-error', errorDetails)
simplePostCall('/api/logs/', errorDetails)
.then((response) => {
notifySuccess('Error successfully sent to backend:' + response);
})
Expand Down

0 comments on commit 8cc6f42

Please sign in to comment.