paperclip icon indicating copy to clipboard operation
paperclip copied to clipboard

Description of status codes

Open omid opened this issue 5 years ago • 3 comments

As @wafflespeanut described in https://github.com/wafflespeanut/paperclip/pull/243#issuecomment-704763049, we can support the following format to be able to add a description for each status code:

#[api_v2_operation(
      status(
          code = 200, description = "OK",
          code = 202, description = "I accept",
      )
)]
fn my_handler () -> Foo { /* */ }

I have an additional suggestion to be able to overwrite the description of the error messages too. Like:

#[api_v2_operation(
      status(
          code = 200, description = "OK",
          code = 202, description = "I accept",
          code = 418, description = "I'm a teapot 🫖",
      )
)]
fn my_handler () -> Foo { /* */ }

@wafflespeanut @platy any idea/suggestion?

omid avatar Oct 12 '20 20:10 omid

You can define error codes with better reusability and convenience via api_v2_errors macros on Error type. There is good example in docs https://paperclip.waffles.space/actix-plugin.html

dunnock avatar Oct 13 '20 05:10 dunnock

Thanks @dunnock.

I'm using that, but it needs to be customized. For example, generally, 404 means Not Found... but for users, it can mean, "The user is inactive or does not exist", for roles it can mean "The role does not exist" and ...

Is there any way of customizing this error per state?

omid avatar Oct 13 '20 08:10 omid

I think we can still have per-handler overrides for error codes, just like how we have it for 2xx or other codes. It will then override the default implementation implemented through #[api_v2_errors] macro.

wafflespeanut avatar Nov 27 '20 14:11 wafflespeanut