Skip to content

Commit

Permalink
ref(types): deprecate enum and export type
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBa committed Dec 16, 2021
1 parent 1dbeeda commit b177690
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
4 changes: 3 additions & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export {
SessionFlusherLike,
} from './session';

/* eslint-disable deprecation/deprecation */
/* eslint-disable-next-line deprecation/deprecation */
export { Severity } from './severity';
export { SeverityLevel, SeverityLevels } from './severity';
export { Span, SpanContext } from './span';
export { StackFrame } from './stackframe';
export { Stacktrace } from './stacktrace';
/* eslint-disable-next-line deprecation/deprecation */
export { Status } from './status';
export { StatusType } from './status';
export {
CustomSamplingContext,
Measurements,
Expand Down
1 change: 0 additions & 1 deletion packages/types/src/severity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** JSDoc
* @deprecated Use string literals - if you require type casting, cast to SeverityLevel type
*/
// eslint-disable-next-line import/export
export enum Severity {
/** JSDoc */
Fatal = 'fatal',
Expand Down
34 changes: 4 additions & 30 deletions packages/types/src/status.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** The status of an event. */
// eslint-disable-next-line import/export
/** JSDoc
* @deprecated Use string literals - if you require type casting, cast to StatusType type
*/
export enum Status {
/** The status could not be determined. */
Unknown = 'unknown',
Expand All @@ -15,31 +16,4 @@ export enum Status {
Failed = 'failed',
}

// eslint-disable-next-line @typescript-eslint/no-namespace, import/export
export namespace Status {
/**
* Converts a HTTP status code into a {@link Status}.
*
* @param code The HTTP response status code.
* @returns The send status or {@link Status.Unknown}.
*/
export function fromHttpCode(code: number): Status {
if (code >= 200 && code < 300) {
return Status.Success;
}

if (code === 429) {
return Status.RateLimit;
}

if (code >= 400 && code < 500) {
return Status.Invalid;
}

if (code >= 500) {
return Status.Failed;
}

return Status.Unknown;
}
}
export type StatusType = 'unknown' | 'skipped' | 'rate_limit' | 'invalid' | 'failed' | 'success';
26 changes: 26 additions & 0 deletions packages/utils/src/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { StatusType } from '@sentry/types';
/**
* Converts an HTTP status code to sentry status {@link StatusType}.
*
* @param code number HTTP status code
* @returns StatusType
*/
export function fromHttpCode(code: number): StatusType {
if (code >= 200 && code < 300) {
return 'success';
}

if (code === 429) {
return 'rate_limit';
}

if (code >= 400 && code < 500) {
return 'invalid';
}

if (code >= 500) {
return 'failed';
}

return 'unknown';
}

0 comments on commit b177690

Please sign in to comment.