blacksky-algorithms / rsky

An AT Protocol Implementation built in Rust.
https://blackskyweb.xyz
Apache License 2.0
136 stars 8 forks source link

PDS: Better Error Messages #8

Open rudyfraser opened 4 months ago

rudyfraser commented 4 months ago

Implement error handling and responses for all endpoints that returns the most appropriate status code for a given error and outputs messages that match the canonical Typescript PDS repo and/or lexicon outputs.

A flexible way to handle this (from the Rocket.rs docs) is using an enum that derives Responder as follows:


use rocket::fs::NamedFile;

#[derive(Responder)]
enum Error {
    #[response(status = 500, content_type = "json")]
    A(String),
    #[response(status = 404)]
    B(NamedFile, ContentType),
    C {
        inner: (Status, Option<String>),
        header: ContentType,
    }
}```