• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FIWARE / contract-management / #14

26 Sep 2023 06:16AM UTC coverage: 1.63%. First build
#14

Pull #1

pulledtim
remove IDE dependent stuff
Pull Request #1: init

143 of 143 new or added lines in 11 files covered. (100.0%)

241 of 14788 relevant lines covered (1.63%)

0.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.74
/src/main/java/org/fiware/iam/exception/CatchAllExceptionHandler.java
1
package org.fiware.iam.exception;
2

3
import io.micronaut.context.annotation.Requires;
4
import io.micronaut.http.HttpRequest;
5
import io.micronaut.http.HttpResponse;
6
import io.micronaut.http.HttpStatus;
7
import io.micronaut.http.annotation.Produces;
8
import io.micronaut.http.server.exceptions.ExceptionHandler;
9
import jakarta.inject.Singleton;
10
import lombok.extern.slf4j.Slf4j;
11
import org.fiware.iam.tmforum.product.server.model.ErrorVO;
12

13
import java.time.format.DateTimeParseException;
14

15
/**
16
 * Handler to catch and log all unexpected exceptions and translate them into a proper 500 response.
17
 */
18
@Produces
19
@Singleton
20
@Requires(classes = {Exception.class, ExceptionHandler.class})
21
@Slf4j
1✔
22
public class CatchAllExceptionHandler implements ExceptionHandler<Exception, HttpResponse<ErrorVO>> {
1✔
23

24
    @Override
25
    public HttpResponse<ErrorVO> handle(HttpRequest request, Exception exception) {
26
        log.warn("Received unexpected exception {} for request {}.", exception.getMessage(), request, exception);
1✔
27
        if (exception instanceof DateTimeParseException dateTimeParseException) {
1✔
28
            return HttpResponse.status(HttpStatus.BAD_REQUEST)
×
29
                    .body(
×
30
                            new ErrorVO().status(HttpStatus.BAD_REQUEST.toString())
×
31
                                    .reason(HttpStatus.BAD_REQUEST.getReason())
×
32
                                    .message(String.format("Request could not be answered due to an invalid date: %s.",
×
33
                                            dateTimeParseException.getParsedString())));
×
34
        }
35
        if (exception instanceof TMForumException tmForumException) {
1✔
36
            return HttpResponse.status(HttpStatus.BAD_GATEWAY)
×
37
                    .body(
×
38
                            new ErrorVO().status(HttpStatus.BAD_GATEWAY.toString())
×
39
                                    .reason(HttpStatus.BAD_GATEWAY.getReason())
×
40
                                    .message(String.format("Request could not be answered due to error in downstream service: %s.",
×
41
                                            tmForumException.getMessage())));
×
42
        }
43
        if (exception instanceof IllegalArgumentException illegalArgumentException) {
1✔
44
            return HttpResponse.status(HttpStatus.BAD_REQUEST)
1✔
45
                    .body(
1✔
46
                            new ErrorVO().status(HttpStatus.BAD_REQUEST.toString())
1✔
47
                                    .reason(HttpStatus.BAD_REQUEST.getReason())
1✔
48
                                    .message(String.format(illegalArgumentException.getMessage())));
1✔
49
        }
50
        return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR)
×
51
                .body(new ErrorVO().status(HttpStatus.INTERNAL_SERVER_ERROR.toString())
×
52
                        .reason(HttpStatus.INTERNAL_SERVER_ERROR.getReason())
×
53
                        .message("Request could not be answered due to an unexpected internal error."));
×
54
    }
55
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc