I am currently looking into implementing some JSON RPC 2.0 responses in my code. However, I'm a little unclear on what are the standard practices of using it:
1) When the user sends a request with invalid parameters, should I just return verbatim default error message
{"jsonrpc": "2.0", "error": {"code": -32602, "message": " Invalid params"}, "id": "1"}
Or can the message be more specific, like:
{"jsonrpc": "2.0", "error": {"code": -32602, "message": " Invalid params: invalid username"}, "id": "1"}
Or should such custom messages have their own error code?
2) If the user say, requests data from the database and the response is "data is not present", as in we encountered no errors but still didn't return anything, should that be returned as a JSON RPC error, or should it be more of response indicating data wasn't found? In other words, is the convention in JSON RPC to use errors as normal return conditions like in Google Go, or is it more akin to "something really messed up" panics?
According to the specification (http://www.jsonrpc.org/specification#error_object) you must use the optional property data for your additional information about the error, so, in your case the response must be:
{"jsonrpc": "2.0", "error": {"code": -32602, "message": " Invalid params", "data":"invalid username"}, "id": "1"}
You can create your own personal error codes in the range -32000 to -32099, but I would do it only when necessary, that is, unless your client application should behave in this case ("invalid username") different than in any other -32602 case.
That is up to you. It is a design question with a broader scope than JSON-RCP. You can find some opinions at this post: when-to-throw-an-exception
Related
When fetching GET https://api.podio.com/item/1259778758 (other items work fine), I get the following error:
HTTP 500
with response body:
{
"error_parameters": {},
"error_detail": null,
"error_propagate": false,
"request": {
"url": "http://api.podio.com/item/1259778758",
"query_string": "",
"method": "GET"
},
"error_description": "An unexpected error occured during execution",
"error": "unexpected"
}
I assume this is due to some field value, but cannot figure this out. Can you please check an fix this?
Additional notes:
It is not possible to open this item in the browser as well
The filter operation in the API fails as well when this item is in the result.
It sounds like this should be escalated with Podio technical support.
I am looking at getting Cherwell talking to Zabbix but stumbling at what I understand is the easiest starting point. I have a user setup in Cherwell as part of the webservice which I have confirmed I can log into Zabbix with.
As part of the web call I am performing the basic Zabbix version check.
{
"jsonrpc": "2.0",
"method": "apiinfo.version",
"params": {},
"id": 1
}
I am getting a -32600 error, Invalid Request, data: the received JSON is not a valid JSON-RPC request.
From what I have read you should be able to do this even if you are not authenticated.
I am though getting back a result code of 200 which means the connection is solid but just not returning what I am expecting.
Thanks
That error usually means the double quotes are missing, missplaced, or escaped in a wrong way. The code by itself is fine.
#API_URL=https://.../zabbix/api_jsonrpc.php
#CONTENT_TYPE=Content-Type: application/json-rpc
{
"jsonrpc": "2.0",
"method": "apiinfo.version",
"id": 1,
"params": {}
}
Using asp.net core 3.1 for a web api, my problem is that when a request comes in with some invalid parameters, the framework produces an error message that I don't want returned in the response.
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "|968ad6dd-4488d8bc10ec5760.",
"errors": {
"$.value": [
"The JSON value could not be converted to System.String. Path: $.value | LineNumber: 1 | BytePositionInLine: 15."
]
}
}
Is it possible to change this error response to something else? Ideally, I'd want to reduce the verbosity and not return the error message ("The JSON value could not be converted to System.String").
app.UseExceptionHandler does not work. ExceptionMiddleware does not work because await _next(httpContext); does not throw an exception.
Thank you in advance.
It seems that one possible way is to play with this: https://github.com/dotnet/aspnetcore/blob/5ff9ed68d1cf6c89d72d27a69b00ed0ecd34daed/src/Mvc/Mvc.Core/src/Infrastructure/ModelStateInvalidFilter.cs
Either set _apiBehaviorOptions.SuppressModelStateInvalidFilter or create a custom InvalidModelStateResponseFactory. Haven't tried it yet, but seems like a potential solution.
{
"errors": [
{
"code": "38189",
"title": "Internal error",
"detail": "An internal error occured, please contact your administrator",
"status": "500"
}
]
}
I get this error when I use production key to send requests to AMADEUS API, this error returns just with production key but not with test key. Despite I updated header to " Accept application/vnd.amadeus+json" the error still returns.
Here one of the requests:
https://api.amadeus.com/v1/shopping/flight-offers?origin=MAD&destination=PAR&departureDate=2019-08-01&adults=1&nonStop=false&max=6
We had a configuration issue on our side. Everything has been fixed, You should be able to use all the APIs in production.
Sorry for the inconvenience.
I want to get the result of all INBOX mails and all SENT mails in one API call using the historyID and the history.list Gmail-API.
Refer:
https://developers.google.com/gmail/api/v1/reference/users/history/list
When I am hitting the following GET request :
https://www.googleapis.com/gmail/v1/users/{userID}/history?startHistoryId={historyID}&labelId=SENT&labelId=INBOX
I only get the SENT label messages.
Seems like the API only accepts single & first query param for labelId.
Is there a way to get multiple labelIds' response in a single API call?
I think it would not be possible, I tried making a multiple request and it this response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Invalid label value in query"
}
],
"code": 400,
"message": "Invalid label value in query"
}
}
I would suggest to call it separately for each labelID but you can try filing a feature request for this.
Hope this helps.