Comments (3)
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.
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.
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)
- Don't close connection for in-process request
- Add MaxPayloadSize setting
- Return 431 status when headers are too large HOT 1
- Any chance of supporting GZip, deflate please. HOT 1
- Bug in running secure server
- Implement better handling in event where user fails the request
- Update Workspaces for Dyalog 17.0 Compatibility
- Add support for Swagger UI HOT 2
- Provide setting to kill request-handling thread on connection close
- Simpler `sint` HOT 1
- Seemingly random crashes related to "OSError" "Undefined name: CON000000XX" HOT 6
- All but GET method seem to need a none empty body HOT 3
- Update Jarvis container to run under v19 HOT 2
- Incorrect Conga Version Reported On Starting Server
- Pipelining Causes Server Error HOT 3
- Jarvis Test Suite HOT 1
- Jarvis Threading Model HOT 3
- DOMAIN ERROR using Jarvis with Dyalog 20.0
- Allow for arrays using multipart/form-data content-type HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jarvis.