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

FIWARE / contract-management / #10

21 Sep 2023 01:18PM UTC coverage: 0.21%. First build
#10

Pull #1

pulledtim
more robust
Pull Request #1: init

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

31 of 14772 relevant lines covered (0.21%)

0.0 hits per line

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

0.0
/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
×
22
public class CatchAllExceptionHandler implements ExceptionHandler<Exception, HttpResponse<ErrorVO>> {
×
23

24
    @Override
25
    public HttpResponse<ErrorVO> handle(HttpRequest request, Exception exception) {
26
        log.warn("Received unexpected exception {} for request {}.", exception.getMessage(), request, exception);
×
27
        if (exception instanceof DateTimeParseException dateTimeParseException) {
×
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 IllegalArgumentException illegalArgumentException) {
×
36
            return HttpResponse.status(HttpStatus.BAD_REQUEST)
×
37
                    .body(
×
38
                            new ErrorVO().status(HttpStatus.BAD_REQUEST.toString())
×
39
                                    .reason(HttpStatus.BAD_REQUEST.getReason())
×
40
                                    .message(String.format(illegalArgumentException.getMessage())));
×
41
        }
42
        return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR)
×
43
                .body(new ErrorVO().status(HttpStatus.INTERNAL_SERVER_ERROR.toString())
×
44
                        .reason(HttpStatus.INTERNAL_SERVER_ERROR.getReason())
×
45
                        .message("Request could not be answered due to an unexpected internal error."));
×
46
    }
47
}
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