fastly / Viceroy

Viceroy provides local testing for developers working with Compute.
https://fastly.dev/learning/compute/testing/#running-a-local-testing-server
Apache License 2.0
140 stars 35 forks source link

Return HttpInvalid error instead of FastlyStatus::Error when failed to build Uri #378

Open arayaryoma opened 3 weeks ago

arayaryoma commented 3 weeks ago

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);
    }
};