details of success and error responses in rest api - json

i am writing a rest api in node js and using mssql as my db. I have dilemma regarding the details of success and error responses that the api should return as per rest guidelines. For example if there is an error for key constraints while doing db operations, should the error message be like this
{
"error": {
"code": 500,
"message": "Internal Server Error"
}
}
Or does it needs to be more specific about the error details like the table details. Is it right to give away the internal details through the errors? Does status code needs to be part of the json object? Also, whether the success messages should be more general like "Record created successfully" with 200 code or more specific?

Always think in your final user. If you return the full error message, it will help him? Maybe the user did a wrong request that caused the internal fail. If not, turn it clear and log the error!
For example, when user gets this response, he should repeat the request? Or it's server fault and should wait for fix? So, I suggest something like:
{
"error": {
"code": 1000,
"href": 'http://mywikiapage.com/errors/1000',
"message": "Sorry, we're experiencing some issues. Try again later."
}
}
Note that error code has changed. Its new "custom" code could refer to a wiki page where it gives more details about the error itself. Furthermore, user always can get the 500 result code from HTTP response.
I also would like to suggest the reading of this other SO question

Related

android-publisher verification testing

Hi I am currently working on an app with an in-app-shop. Now I need to implemented Server Side Verification for Google In-app-purchases. We use https://github.com/googleapis/google-api-php-client for the verification. We already got the in app purchases and have tested the in app purchases with the test products (android.test.purchased). Is there a way to test the validation ? In the moment i get the following response when using a "android.test.purchased" for the following call
$googleApiResult = $service->purchases_products->get($_ENV['PACKAGENAME'], $productId, $token);
{
"error": {
"code": 400,
"message": "Invalid Value",
"errors": [
{
"message": "Invalid Value",
"domain": "global",
"reason": "invalid"
}
]
}
}
In the docs it states that you need the productive data. The app has already an Alpha Track. On the alpha track in the Google Store the in app purchases are also approved but cannot get verified by the backend. Since the alpha track is a productive enviroment, we do not have the console or network logs to check whats the problem. What is the best practice here. Is there a way to debug verification ?
In my case the problem is insufficent permission of my Google Client. I used the tokens which we got from the productive enviroment and used them in the local api.

Autodesk-designautomation: Internal Server Error(Error Code 500): Missing parameter in WorkItem

I am using Autodesk Revit and have been trying to implement the Design Automation API. I have been successful in trying out the sample, modify-your-model tutorial where the dimensions of a window are altered. However the example code is not executing perfectly anymore and it displays an internal server error message(error code 500). The error console claims that some parameter in the workItem is missing. The code worked again on the morning of 14th March again, but by noon it started showing the same error. The error log on the web page and console are given below respectively.
My question is, has the Autodesk OSS server been down for some time now or is it some fault from my side? Please help me out.
P.S. The same code worked perfectly before. I have not edited anything. Yes, I did try changing the Client ID and Client Secret and also update the ngrok address every 2hours.
Sincerely
Error list
-Failed to load resource: the server responded with a status of 500 (Internal Server Error)
-No webpage was found for the web address: http://localhost:3000/api/forge/designautomation/workitems
error in debugger
-fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HM76OJJ532MV", Request id "0HM76OJJ532MV:00000002": An unhandled exception was thrown by the application.
System.Net.Http.HttpRequestException: The server returned the non-success status code 400 (Bad Request).
More error details:
{
"url": [
"Error converting value \"http://aa025317d1f2.ngrok.io /api/forge/callback/designautomation?id=76m1z2sw7uQi-jtAYzYvgA&outputFileName=20210314024133_output_revit_sample_file.rvt\" to type 'System.Uri'. Path 'url', line 1, position 2376."
],
"workItem": [
"A value for the 'workItem' parameter or property was not provided."
]
}
As suggested in the comments there is a space in the ngrok url posted to the workitem:
http://aa025317d1f2.ngrok.io /api/forge/callback/designautomation?id=76m1z2sw7uQi-jtAYzYvgA&outputFileName=20210314024133_output_revit_sample_file.rvt

In what format is it best to return an error in REST

What format should I return the response to the API user if an error occurred? Just return the response as a status code and error message:
Full authentication is required to access this resource
(the status 401 was returned)
Or it is better to return it in this format:
{
"timestamp": "2020-06-14T21:20:52.941+0000",
"status": 401,
"error": "Unauthorized",
"message": "Full authentication is required to access this resource",
"path": "/api/users/me"
}
Well, it depends:
If you know your front end urgently requires the direct message of the error, ignoring anything else, then going for the short and direct to the point answer might be your best choice.
But honestly, if experience in programming has taught me anything, is that the more information you have about something, the better, ESPECIALLY IF IT'S an ERROR!!! With the longer response, you have many more tools in you hand, both for giving the final user a better look of your application - You can present for the user a small title, a detailed message and, for example, use an internal code to show a red "error" box if a fatal error ocurred or a "warning" yellow box if a validation simply failed - and especially for the dev to solve that problem (The final user might never see the "timestamp", "status", "path" or stacktrace of the error - He shouldn't... - But it will surely help you track what caused the error).
Take a look at these (1, 2 and 3) articles to help you decide your situation and, if needed, customize your error response structure

Postman HERE API Error on Setup

I'm having an issue setting up to the HERE API using Postman following these two guides: 1, 2.
Anyways, I've loaded the Postman collection, set the global environment and placed in my app-id and app-code (Freemium account) but I still get the following error when trying to get the access token:
{
"msg": "app_id or app_code is wrong",
"kind": "datalens#error",
"code": 402
}
Does anyone have any experience with getting through this? I've tried a million different little variations but I still get the same error. Any help is vastly appreciated. Thanks
Unfortunately the Geovisualization REST API is the only API on the portal that's currently not part of the Freemium plan. I apologize for the unclear error message and will look into improving this. To gain access please contact us through the portal.

Google Drive API files setq sharedWithMe=false causes "500 Internal Server Error"

Is this a bug or am I entering value incorrectly?
To repeat, go to "Try it!" on google sdk files page:
https://developers.google.com/drive/v2/reference/files/list#try-it
Try getting files (you'll need to authorize); then try entering sharedWithMe=false in the setQ field.
I get the following error (interesting that sharedWithMe=true succeeds):
500 Internal Server Error
- Show headers -
{
"error": {
"code": 500,
"message": null
}
}
Anyone know why?