Giter VIP home page Giter VIP logo

Comments (3)

bpbecker avatar bpbecker commented on August 25, 2024

This is an interesting issue and deserves some discussion. It's not only applicable in REST mode, but also in JSON mode when the endpoint function can accept a left argument (which is the request object itself).

There are three types of errors -

  • ones the user anticipates - here the user can set the response payload to whatever he wants. GitHub and OpenAI provide error information in the response payload.
  • ones Jarvis detects - things like bad HTTP method, endpoint not found, etc. Jarvis sets an appropriate HTTP status code and message
  • unexpected errors - This is when then global error trap catches an error in the user code - Jarvis falls back to a 500 Internal Server Error.

We could decide to put information in the response payload. But what if there's already content there? Do we wipe it out and replace it with the error information? Do we append or prepend? My inclination is to do two things:

  • Provide a SendErrorInPayload setting which will direct Fail to replace any existing payload with error information based on ErrorInfoLevel.
  • Provide a "user hook function" setting OnFailFn which is the name of a function that Fail will call, passing the request object as an argument. Then the developer can go to town and do whatever he wants.

from jarvis.

JasonRivers avatar JasonRivers commented on August 25, 2024

On your second point, one way I've dealt with some errors that are not "breaking" errors in APIs is having an error section in the payload, so for a JSON payload something like the following:

{
    "data": {
        "stuff": "actual payload"
    },
    "errors": {
        "errorcode": 123,
        "message": "human readable stuff",
        "details": "Bunch more information"
    }
}

I've also seen other API systems do this, where the "errors" section may or may not exist in the payload.

This way you still get the data that you requested, but if the error exists then your data may be truncated or inaccurate, for full errors, (item not found) I've also seen some APIs only issue and "error" section with a http 404 and the details in the JSON format (rather than HTML), too. - this often depends on the "Accept: application/json" header being set on request.

from jarvis.

bpbecker avatar bpbecker commented on August 25, 2024

I've seen same sort of behavior in other APIs (GitHub and OpenAI for instance). But what to include in the payload is really up to the user. Especially in Jarvis' REST mode, the response could have whatever content-type the application decides. So, I think if the user uses SendErrorInPayload, we'll probably send back information in using application/json and document that if you get a non-2XX HTTP status and have SendErrorInPayload set the error information will be JSON. If the user uses OnFailFn, then he can do whatever his heart desires.

from jarvis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.