@@ -37,51 +37,84 @@ export enum SpanStatus {
3737  DataLoss  =  'data_loss' , 
3838} 
3939
40- // eslint-disable-next-line @typescript-eslint/no-namespace, import/export 
41- export  namespace  SpanStatus  { 
42-   /** 
43-    * Converts a HTTP status code into a {@link  SpanStatus}. 
44-    * 
45-    * @param  httpStatus The HTTP response status code. 
46-    * @returns  The span status or {@link  SpanStatus.UnknownError}. 
47-    */ 
48-   export  function  fromHttpCode ( httpStatus : number ) : SpanStatus  { 
49-     if  ( httpStatus  <  400  &&  httpStatus  >=  100 )  { 
50-       return  SpanStatus . Ok ; 
51-     } 
40+ export  type  SpanStatusType  = 
41+   /** The operation completed successfully. */ 
42+   |  'ok' 
43+   /** Deadline expired before operation could complete. */ 
44+   |  'deadline_exceeded' 
45+   /** 401 Unauthorized (actually does mean unauthenticated according to RFC 7235) */ 
46+   |  'unauthenticated' 
47+   /** 403 Forbidden */ 
48+   |  'permission_denied' 
49+   /** 404 Not Found. Some requested entity (file or directory) was not found. */ 
50+   |  'not_found' 
51+   /** 429 Too Many Requests */ 
52+   |  'resource_exhausted' 
53+   /** Client specified an invalid argument. 4xx. */ 
54+   |  'invalid_argument' 
55+   /** 501 Not Implemented */ 
56+   |  'unimplemented' 
57+   /** 503 Service Unavailable */ 
58+   |  'unavailable' 
59+   /** Other/generic 5xx. */ 
60+   |  'internal_error' 
61+   /** Unknown. Any non-standard HTTP status code. */ 
62+   |  'unknown_error' 
63+   /** The operation was cancelled (typically by the user). */ 
64+   |  'cancelled' 
65+   /** Already exists (409) */ 
66+   |  'already_exists' 
67+   /** Operation was rejected because the system is not in a state required for the operation's */ 
68+   |  'failed_precondition' 
69+   /** The operation was aborted, typically due to a concurrency issue. */ 
70+   |  'aborted' 
71+   /** Operation was attempted past the valid range. */ 
72+   |  'out_of_range' 
73+   /** Unrecoverable data loss or corruption */ 
74+   |  'data_loss' ; 
5275
53-     if  ( httpStatus  >=  400  &&  httpStatus  <  500 )  { 
54-       switch  ( httpStatus )  { 
55-         case  401 :
56-           return  SpanStatus . Unauthenticated ; 
57-         case  403 :
58-           return  SpanStatus . PermissionDenied ; 
59-         case  404 :
60-           return  SpanStatus . NotFound ; 
61-         case  409 :
62-           return  SpanStatus . AlreadyExists ; 
63-         case  413 :
64-           return  SpanStatus . FailedPrecondition ; 
65-         case  429 :
66-           return  SpanStatus . ResourceExhausted ; 
67-         default :
68-           return  SpanStatus . InvalidArgument ; 
69-       } 
70-     } 
76+ /** 
77+  * Converts a HTTP status code into a {@link  SpanStatusType}. 
78+  * 
79+  * @param  httpStatus The HTTP response status code. 
80+  * @returns  The span status or unknown_error. 
81+  */ 
82+ export  function  spanStatusfromHttpCode ( httpStatus : number ) : SpanStatusType  { 
83+   if  ( httpStatus  <  400  &&  httpStatus  >=  100 )  { 
84+     return  'ok' ; 
85+   } 
7186
72-     if  ( httpStatus  >=  500  &&  httpStatus  <  600 )  { 
73-       switch  ( httpStatus )  { 
74-         case  501 :
75-           return  SpanStatus . Unimplemented ; 
76-         case  503 :
77-           return  SpanStatus . Unavailable ; 
78-         case  504 :
79-           return  SpanStatus . DeadlineExceeded ; 
80-         default :
81-           return  SpanStatus . InternalError ; 
82-       } 
87+   if  ( httpStatus  >=  400  &&  httpStatus  <  500 )  { 
88+     switch  ( httpStatus )  { 
89+       case  401 :
90+         return  'unauthenticated' ; 
91+       case  403 :
92+         return  'permission_denied' ; 
93+       case  404 :
94+         return  'not_found' ; 
95+       case  409 :
96+         return  'already_exists' ; 
97+       case  413 :
98+         return  'failed_precondition' ; 
99+       case  429 :
100+         return  'resource_exhausted' ; 
101+       default :
102+         return  'invalid_argument' ; 
83103    } 
104+   } 
84105
85-     return  SpanStatus . UnknownError ; 
106+   if  ( httpStatus  >=  500  &&  httpStatus  <  600 )  { 
107+     switch  ( httpStatus )  { 
108+       case  501 :
109+         return  'unimplemented' ; 
110+       case  503 :
111+         return  'unavailable' ; 
112+       case  504 :
113+         return  'deadline_exceeded' ; 
114+       default :
115+         return  'internal_error' ; 
116+     } 
86117  } 
118+ 
119+   return  'unknown_error' ; 
87120} 
0 commit comments