HttpStatusRange
Package: @opra/common
HttpStatusRange is a small value class that represents an HTTP status code or a contiguous range of status codes (e.g. 200, 400-499, 2xx). It is used on HttpOperationResponse to declare which status codes a response covers.
Constructor
new HttpStatusRange(statusCode: number)
new HttpStatusRange(start: number, end: number)
new HttpStatusRange(rangeString: string) // e.g. '200', '400-499', '2xx'
new HttpStatusRange(init: { start: number; end: number })
| Form | Example | Result |
|---|---|---|
| Single code | new HttpStatusRange(200) | start: 200, end: 200 |
| Code range | new HttpStatusRange(400, 499) | start: 400, end: 499 |
| Range string | new HttpStatusRange('400-499') | start: 400, end: 499 |
Throws TypeError for invalid range strings.
Properties
| Property | Type | Description |
|---|---|---|
start | number | First status code in the range (inclusive). |
end | number | Last status code in the range (inclusive). Equal to start for a single code. |
Methods
includes(statusCode)
Returns true if statusCode falls within this range.
const range = new HttpStatusRange(400, 499);
range.includes(404); // true
range.includes(200); // false
includes(statusCode: number): boolean
intersects(start, end)
Returns true if this range overlaps with the given range.
range.intersects(404, 422); // true — overlaps with 400-499
range.intersects(200, 299); // false
intersects(start: number, end: number): boolean
toString()
Returns a human-readable string representation.
new HttpStatusRange(200).toString(); // '200'
new HttpStatusRange(400, 499).toString(); // '400-499'
toJSON()
Returns number for a single code, or { start, end } for a range.
toJSON(): number | { start: number; end: number }