Viceroy
Viceroy copied to clipboard
Return HttpInvalid error instead of FastlyStatus::Error when failed to build Uri
Fastly Rust SDK maps FastlyStatus::Error
to BackendCreationError::NameInUse
.
By this, when we passed invalid host name value to fastly::Backend::builder
func, we always received NameInUse
error.
It's a misleading behavior for developers, who will assume they register the same backend multiple times.
In this PR, I defined a new internal Error InvalidBackendUrl
and map it as FastlyStatus::HttpInvalid
.
It will help developers to awake they are using invalid URI to build the dynamic backend.
Example
before
let backend = match fastly::Backend::builder("example", "http://example.com").finish() {
Ok(backend) => backend,
Err(e) => {
println!("Error: {:?}", e); // Error: NameInUse
return Err(e);
}
};
after
let backend = match fastly::Backend::builder("example", "http://example.com").finish() {
Ok(backend) => backend,
Err(e) => {
println!("Error: {:?}", e); // Error: HostError(FastlyStatus::HTTP_INVALID_ERROR)
return Err(e);
}
};