File Coverage

blib/lib/Sentry/Tracing/Status.pm
Criterion Covered Total %
statement 25 46 54.3
branch 12 24 50.0
condition 2 3 66.6
subroutine 8 21 38.1
pod 0 18 0.0
total 47 112 41.9


line stmt bran cond sub pod time code
1             package Sentry::Tracing::Status;
2 10     10   30337 use Mojo::Base -base, -signatures;
  10         19  
  10         82  
3              
4 10     10   3324 use experimental qw(switch);
  10         26  
  10         36  
5 10     10   691 use HTTP::Status qw(:constants);
  10         19  
  10         13745  
6              
7             # The operation completed successfully.
8 11     11 0 55 sub Ok {'ok'}
9              
10             # Deadline expired before operation could complete.
11 0     0 0 0 sub DeadlineExceeded {'deadline_exceeded'}
12              
13             # 401 Unauthorized (actually does mean unauthenticated according to RFC 7235)
14 0     0 0 0 sub Unauthenticated {'unauthenticated'}
15              
16             # 403 Forbidden
17 0     0 0 0 sub PermissionDenied {'permission_denied'}
18              
19             # 404 Not Found. Some requested entity (file or directory) was not found.
20 1     1 0 5 sub NotFound {'not_found'}
21              
22             # 429 Too Many Requests
23 0     0 0 0 sub ResourceExhausted {'resource_exhausted'}
24              
25             # Client specified an invalid argument. 4xx.
26 0     0 0 0 sub InvalidArgument {'invalid_argument'}
27              
28             # 501 Not Implemented
29 0     0 0 0 sub Unimplemented {'unimplemented'}
30              
31             # 503 Service Unavailable
32 1     1 0 6 sub Unavailable {'unavailable'}
33              
34             # Other/generic 5xx.
35 2     2 0 11 sub InternalError {'internal_error'}
36              
37             # Unknown. Any non-standard HTTP status code.
38 0     0 0 0 sub UnknownError {'unknown_error'}
39              
40             # The operation was cancelled (typically by the user).
41 0     0 0 0 sub Cancelled {'cancelled'}
42              
43             # Already exists (409)
44 0     0 0 0 sub AlreadyExists {'already_exists'}
45              
46             # Operation was rejected because the system is not in a state required for the operation's
47 0     0 0 0 sub FailedPrecondition {'failed_precondition'}
48              
49             # The operation was aborted, typically due to a concurrency issue.
50 0     0 0 0 sub Aborted {'aborted'}
51              
52             # Operation was attempted past the valid range.
53 0     0 0 0 sub OutOfRange {'out_of_range'}
54              
55             # Unrecoverable data loss or corruption
56 0     0 0 0 sub DataLoss {'data_loss'}
57              
58 15     15 0 338759 sub from_http_code ($package, $code) {
  15         83  
  15         46  
  15         25  
59 15 100       105 return Sentry::Tracing::Status->Ok if $code < HTTP_BAD_REQUEST;
60              
61 4 100 66     27 if ($code >= HTTP_BAD_REQUEST && $code < HTTP_INTERNAL_SERVER_ERROR) {
62 1 50       5 if ($code == HTTP_UNAUTHORIZED) { return Unauthenticated() }
  0 50       0  
    50          
    0          
    0          
    0          
63 0         0 elsif ($code == HTTP_FORBIDDEN) { return PermissionDenied() }
64 1         5 elsif ($code == HTTP_NOT_FOUND) { return NotFound() }
65 0         0 elsif ($code == HTTP_CONFLICT) { return AlreadyExists() }
66 0         0 elsif ($code == HTTP_PRECONDITION_FAILED) { return FailedPrecondition() }
67 0         0 elsif ($code == HTTP_TOO_MANY_REQUESTS) { return ResourceExhausted() }
68 0         0 else { return InvalidArgument() }
69             }
70              
71 3 50       13 if ($code >= HTTP_INTERNAL_SERVER_ERROR) {
72 3 50       32 if ($code == HTTP_NOT_IMPLEMENTED) { return Unimplemented() }
  0 100       0  
    50          
73 1         4 elsif ($code == HTTP_SERVICE_UNAVAILABLE) { return Unavailable() }
74 0         0 elsif ($code == HTTP_GATEWAY_TIMEOUT) { return DeadlineExceeded() }
75 2         6 else { return InternalError() }
76             }
77             }
78              
79             1;