HttpStatus.fromCode constructor
HttpStatus.fromCode(
- int code
Constructs an instance of HttpStatus
based on a predefined list of
status codes.
If the given code is not found within the predefined list,
it throws an ArgumentError
, suggesting the use of
the main constructor to define custom codes.
try {
var myStatus = HttpStatus.fromCode(450);
} catch (e) {
print(e); // Unrecognized status code. Use the HttpStatus constructor for custom codes
}
Implementation
factory HttpStatus.fromCode(int code) {
if (!_httpStatusCodes.containsKey(code)) {
throw ArgumentError.value(
code,
'code',
'Unrecognized status code. Use the HttpStatus constructor for custom codes',
);
}
return _httpStatusCodes[code]!;
}