restful-api-description-language / RADL

RADL: A description language and tooling for hypermedia-driven RESTful APIs
Apache License 2.0
23 stars 5 forks source link

Add status to <error> element #42

Closed RaySinnema closed 9 years ago

RaySinnema commented 9 years ago

Should we add a status attribute to the error element?

This is not so much for clients, who shouldn't tightly couple to status codes, but more for servers. For instance, we could use this information to generate exception classes and a central exception-to-status mapper.

Here's an example error condition for RESTBucks:

<error name="http://errors.restbucks.com/invalid-item" status="400">
  <documentation>
    The attributes you provided are invalid for the requested menu item.
  </documentation>
</error>

And here's the Spring code we could generate from that:

/**
 * The attributes you provided are invalid for the requested menu item.
 */
public class InvalidItemException extends IllegalArgumentException {

  public InvalidItemException() {
    super("http://errors.restbucks.com/invalid-item");
  }

}

@ControllerAdvice
public class CentralErrorHandler {

  @ExceptionHandler({ IllegalArgumentException.class })
  public ResponseEntity<String> illegalArgument(IllegalArgumentException e) {
    return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
  }

}

Without the status attribute, we wouldn't know what base class to generate for InvalidItemException.

RaySinnema commented 9 years ago

See also #39.

jonathanrobie commented 9 years ago

The use case makes sense. Three questions / suggestions:

RaySinnema commented 9 years ago

Yes. No. OK.

RaySinnema commented 9 years ago

The proposal is:

error = element error { name, error-status-code?, documentation* }
error-status-code = attribute status-code { HTTP-status-enum }
jonathanrobie commented 9 years ago

Let's leave the issue open until William responds, but I'll add it to the schema right now.

On Wed, Sep 9, 2015 at 4:06 AM, Rémon (Ray) Sinnema < notifications@github.com> wrote:

The proposal is:

error = element error { name, error-status-code?, documentation* } error-status-code = attribute status-code { HTTP-status-enum }

— Reply to this email directly or view it on GitHub https://github.com/restful-api-description-language/RADL/issues/42#issuecomment-138818679 .

gentlewind commented 9 years ago

+1