Skip to content

Commit b177690

Browse files
committed
ref(types): deprecate enum and export type
1 parent 1dbeeda commit b177690

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

packages/types/src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ export {
3232
SessionFlusherLike,
3333
} from './session';
3434

35-
/* eslint-disable deprecation/deprecation */
35+
/* eslint-disable-next-line deprecation/deprecation */
3636
export { Severity } from './severity';
3737
export { SeverityLevel, SeverityLevels } from './severity';
3838
export { Span, SpanContext } from './span';
3939
export { StackFrame } from './stackframe';
4040
export { Stacktrace } from './stacktrace';
41+
/* eslint-disable-next-line deprecation/deprecation */
4142
export { Status } from './status';
43+
export { StatusType } from './status';
4244
export {
4345
CustomSamplingContext,
4446
Measurements,

packages/types/src/severity.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/** JSDoc
22
* @deprecated Use string literals - if you require type casting, cast to SeverityLevel type
33
*/
4-
// eslint-disable-next-line import/export
54
export enum Severity {
65
/** JSDoc */
76
Fatal = 'fatal',

packages/types/src/status.ts

+4-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/** The status of an event. */
2-
// eslint-disable-next-line import/export
1+
/** JSDoc
2+
* @deprecated Use string literals - if you require type casting, cast to StatusType type
3+
*/
34
export enum Status {
45
/** The status could not be determined. */
56
Unknown = 'unknown',
@@ -15,31 +16,4 @@ export enum Status {
1516
Failed = 'failed',
1617
}
1718

18-
// eslint-disable-next-line @typescript-eslint/no-namespace, import/export
19-
export namespace Status {
20-
/**
21-
* Converts a HTTP status code into a {@link Status}.
22-
*
23-
* @param code The HTTP response status code.
24-
* @returns The send status or {@link Status.Unknown}.
25-
*/
26-
export function fromHttpCode(code: number): Status {
27-
if (code >= 200 && code < 300) {
28-
return Status.Success;
29-
}
30-
31-
if (code === 429) {
32-
return Status.RateLimit;
33-
}
34-
35-
if (code >= 400 && code < 500) {
36-
return Status.Invalid;
37-
}
38-
39-
if (code >= 500) {
40-
return Status.Failed;
41-
}
42-
43-
return Status.Unknown;
44-
}
45-
}
19+
export type StatusType = 'unknown' | 'skipped' | 'rate_limit' | 'invalid' | 'failed' | 'success';

packages/utils/src/status.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { StatusType } from '@sentry/types';
2+
/**
3+
* Converts an HTTP status code to sentry status {@link StatusType}.
4+
*
5+
* @param code number HTTP status code
6+
* @returns StatusType
7+
*/
8+
export function fromHttpCode(code: number): StatusType {
9+
if (code >= 200 && code < 300) {
10+
return 'success';
11+
}
12+
13+
if (code === 429) {
14+
return 'rate_limit';
15+
}
16+
17+
if (code >= 400 && code < 500) {
18+
return 'invalid';
19+
}
20+
21+
if (code >= 500) {
22+
return 'failed';
23+
}
24+
25+
return 'unknown';
26+
}

0 commit comments

Comments
 (0)