AMWA-TV / is-13

AMWA IS-13 NMOS Annotation Specification [Work In Progress]
https://specs.amwa.tv/is-13
Apache License 2.0
1 stars 1 forks source link

Better status codes for PATCH requests #23

Closed alabou closed 1 year ago

alabou commented 1 year ago

The current API uses the 501 Internal Server Error status for conditions that are not errors of the server or unexpected errors but known conditions that may arise in the use of the API.

I would propose using the following status code for the PATCH method for conditions that are allowed by the API and expected from some implementations.

405 Method Not Allowed Returned when the implementation does not support the annotation API for a specific resource. Client shall not retry the request.

422 Unprocessable Content Returned when the implementation does not support the annotation API request: string too long, read-only tag, too many tags values, too many tags, etc. Client shall not retry the request. It shall modify the request based on the detailed status message before retrying.

507 Insufficient Storage Returned when the implementation does not have more space for storing annotations. Client shall not retry the request.

garethsb commented 1 year ago

I think this is worth considering.

I'm not sure about the use case for 405 Method Not Allowed. Why not, if the Annotation API is not supported for a resource, just don't include it in the API?

422 Unprocessable Content is not used in any published AMWA NMOS spec, but is proposed to be used in IS-11. I think it could be appropriate.

507 Insufficient Storage is not defined in the HTTP spec but in the WebDAV spec, but I don't think that should stop us using it if the semantics are right - we also use 423 Locked defined in that spec.

We should make clear about the distinction between "string too long, too many tags values, too many tags, etc." and "does not have more space"... I think it's the difference between (unstated/undiscoverable because we haven't added an endpoint to the API) constraints in a spec of a tag or the spec of this product, vs. current lack of persistent storage, right?

peterbrightwell commented 1 year ago

Discussion 2023-06-01:

API implementation is responsible for which resources are supported, so 404 would do for cases where the Annotation API isn't supported. If it's a dynamic resource and can't be annotated, don't put it in the API. IS-13 provides a list of resources on a GET. These are not guaranteed to still exist on a a latter request, which is probably ok (and is consistent with the non-atomic nature of much of NMOS). See also #9. WA: 405 not needed.

422 and 507 ideas accepted. RAML description states (without normative language) when a particular status code is used, and the documentation says "Where the RAML specification of an API specifies explicit response codes it is expected that a client will handle these cases in a particular way. "

We should set a minimum requirement for length of string etc that implementations must support. This will help testing. Action all to agree this.

Action @garethsb draft a PR and all consider implementation. Consider what it might mean for e.g. an Ansible playbook for annotations.

garethsb commented 1 year ago

I'm looking at the existing language:

Read-Only Tags

Some named tags, such as those defined by BCP-002-01 and BCP-002-02, or by a particular manufacturer, are intended to have read-only values assigned to the resources by the manufacturer.

An API implementation MAY therefore reject requests to update specific named tags, with a 500 (Internal Server Error) response.

A PATCH request with tags set to null does not update read-only tags.

Additional Limitations

Some named tags have additional limitations, such as needing precisely one element in the array of values. An API implementation SHOULD reject requests which do not meet the additional limitations specified for such tags, with a 500 (Internal Server Error) response.

An API implementation MAY have additional limitations such as:

  • maximum length of strings used as labels, descriptions or tag values
  • maximum number of values for each named tag
  • maximum number of tags (per resource)
  • maximum total size of annotations per resource or across all resources

The API implementation MAY reject requests which it cannot process, with a 500 (Internal Server Error) response.

How would we divvy up these different limitations to 422 (Unprocessable Content) or 507 (Insufficient Storage)?

If they are limitations on particular tags, due to a specification for that tag, e.g. that urn:x-nmos:tag:asset:manufacturer/v1.0 is read-only, or that urn:x-manfacturer:tag:foo must meet a certain syntax or must have precisely one value, then the client error 422 would seem appropriate, even if a client couldn't be expected to know the specification of every tag that it came across.

How about maximum lengths of strings for labels or descriptions or urn:x-nmos:tag:user: tags? Or a general limitation that the vendor/device only supports single values per tag? These seem a little different, arbitrary vendor decisions, somehow?

Then there's the "maximum total size of annotations per resource or across all resources" (two separate possible conditions) for which server error 507 might be appropriate.

What do you think, @alabou @cristian-recoseanu ?

We do definitely need @timhall99 user guidance as well as vendor input on whether/what minimums we should write into the spec for label, description and tag value supported lengths (as well as actually, tag name length!) and numbers of values per tag, numbers of tags per resource, etc.

alabou commented 1 year ago

discovering limitations:

peterbrightwell commented 1 year ago

Update 2023-07-13: no discussion this time. We need to resolve next week when @alabou is available.

peterbrightwell commented 1 year ago

Update 2023-07-20: we can leave as only 500 in this first phase, no need to delay this iteration. For many use cases an error message will be useful as there will be a user on hand and no need for automated action to deal with specific error cases.