since approximately half an hour i'm experiencing error 400 when trying to retrieve data from Parse via the javascript sdk.
I got the following errors :
POST https://api.parse.com/1/classes/LocalQuestion 400 (Bad Request)
b.Error {code: 159, message: "Failed to initialize mongo connection"}
This affect some of my apps, but not all of them. For those which have this problem the dashboard isn't accessible. (I receive an error message saying that something went wrong.
Related
As the title says, I'm trying to write a bunch of records to timestream, but I keep getting "ValidationException" without any further information, so I have no idea what should be fixed. The exact error response is:
operation error Timestream Write: WriteRecords, https response error StatusCode: 400, RequestID: XXXXXXXXXXXXXX, ValidationException:
It made me think that it was a multiline string and somehow the logging framework wasn't logging properly, but I tried splitting by \n and all I got was a size 1 list with the same text.
Any ideas?
For some reason, the validation error is wrapped multiple errors deep. To get to the validation error message, you need the following:
import (
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/transport/http"
"github.com/aws/aws-sdk-go-v2/service/timestreamwrite/types"
"github.com/aws/smithy-go"
)
responseError := err.(*smithy.OperationError).Unwrap().(*http.ResponseError)
validationError := responseError.Unwrap().(*types.ValidationException)
fmt.Println(validationError.ErrorMessage())
im currently working on a website which has Spring at backend and Angularjs at front side and we had discussed about back end responses to handle frontend's message dialogs and i have a question to ask:
Lets say i have an API :
GET : /getstatistics
Request params : fromTime,toTime ( in timestamp format)
And if client make a request with invalid params like a string, which response code should be returned from server ? HTTP 400 bad request and response body with a message " fromTime and toTime should be in timestamp format" or HTTP 200 with same message?
I saw some Google's APIs for example Oauth, they're returning code 200 for a request with invalid access_token but ,in our project my opinion it should be HTTP 400 because Javascript has success and error callbacks, is it better for it just pop a red color dialog with message inside rather than a HTTP 200 code then still need to check the content of the message?
Any advides and opinions are appreciated.
Thanks!
You should be returning a 400 error for bad request. Check out this reference.
The server cannot or will not process the request due to something
that is perceived to be a client error (e.g., malformed request
syntax, invalid request message framing, or deceptive request
routing).
Please have a look at RFC7231#section-6
A client MUST understand the class of any status code, as indicated by
the first digit
and,
4xx (Client Error): The request contains bad syntax or cannot be
fulfilled
Bad syntax can be something like you've mentioned in your question (making a request with invalid parameters, like a string).
I keep these two references handy whenever I'm designing RESTful APIs, might be helpful for you too:
https://httpstatuses.com/
http://www.restapitutorial.com/httpstatuscodes.html
Yes you are right, the http code should be 400 in your case. Your discussion here normally should be whether you need to return 400 or 422. For this you can check the accepted response for this SO question 400 vs 422 response to POST of data
I think it has something to do with how the parameters are used. If you use the resource, then a 404 should return. If the data is simply not valid then we decide to set a 409 Status to the request. It can't full fill it at 100% because of missing/invalid parameter.
HTTP Status Code "409 Conflict" was for us a good try because it's
definition require to include enough information for the user to
recognize the source of the conflict.
Reference: w3.org/Protocols/
Edit:
In any case, the status code 200 is incorrect here because there is an error. In response, you can then return specific information like this:
{
"errors": [
{
"userMessage": "Sorry, the parameter xxx is not valid",
"internalMessage": "Invalid Time",
"code": 34,
"more info": "http://localhost/"
}
]
}
I have a bunch of PUT operations which execute actions on the input resource.
Let's make an example: I have a payment operation in my API which state that a credit card must be charged by a specific Amount.
In my code I first verify if there is sufficient credit on the card and then execute the operation. If there is'nt sufficient amount I simply return 400 but I am not sure it is correct.
Which is the correct HTTP Status Code in cases like this?
I can, of course send a response with HTTP 200 and attach a payload with further details explaining the error. I can also send back an HTTP 400 Bad Request or even better an HTTP 412 Precondition Failed.
Which is the correct code to send in the response in scenario like this where the validation failed? Is there any resource that I can read to understand the rationale behind HTTP Status Codes and HTTP Verbs?
Use 422 Unprocessable Entity.
The 422 status code means the server understands the content type of the request entity (hence a 415 Unsupported Media Type status code is inappropriate), and the syntax of the request entity is correct (thus a 400 Bad Request status code is inappropriate) but was unable to process the contained instructions.
Failing that, simply use 400 for any error having to do with your business domain. As of June 2004, the description for error 400 was amended to read:
The server cannot or will not process the request due to something that is perceived to be a client error
If the operation failed because of data sent by the user (it seems to be the case), you should use status codes 400 (general) or 422 (more precise but coming from the WebDAV spec). You can return back additional hints about the error within the payload (the structure is up to you) like:
{
error: {
"field": "amount",
"message": "The amount isn't correct - Sufficient credit."
}
}
I think that code 412 doesn't apply here since it must be returned when your server doesn't meet a condition specified by the client (see headers If-* like If-Match, If-Modified-Since, ...).
Hope it helps you,
Thierry
IMO: I would stick with 200 and then parse out the response and deal with that. HTTP status codes are protocol status code, not something that you should use for dealing with application logic.
{
"error": {
"field": "amount",
"message": "The amount isn't correct - Sufficient credit."
}
}
In case of the above code, the service call worked fine warranting a return code 200. However, you application logic now needs to deal with the error reported.
If we are using a HTTP status code to indicate error, we will start to get flagged in our logs etc. even though there was no technical error.
Sometimes our GCS upload requests (from App Engine, if that matters) fail with the error "Call error 5". I'm afraid I don't know the actual HTTP status code returned because we are using the google-go-api-client which does some parsing of responses and (if the response is a JSON-formatted error message) only returns the error message itself in the returned error struct.
I presume that "Call error 5" indicates some kind of transient problem on Google's side, but I'd like to confirm this just to be sure...
There is a limit of 10 MB per request and 32 MB per response. Please see: https://developers.google.com/appengine/docs/go/urlfetch/#Go_Quotas_and_limits
I'm using a little code to grab an image given its URL, and it's working for me for all URLs I tried except one:
http://title.mximg.com/img/logo/bizrealty.com.gif
For this URL, I'm getting "The underlying connection was closed: An unexpected error occurred on a receive."
However, if you open that URL with a browser, it loads perfectly.
Apparently that error message means:
"The underlying connection was closed:
An unexpected error occurred on a
receive."
--Seen when the client had sent the request in its entirety and got a TCP
ACK-FIN or RST from server to close
the connection, without a response
from server.
But I have no idea what that means :-(
The code is simply:
Dim req As System.Net.HttpWebRequest = DirectCast(WebRequest.Create(ImageURL), HttpWebRequest)
req.Method = "GET"
Dim resp As Net.HttpWebResponse = DirectCast(req.GetResponse(), Net.HttpWebResponse)
UPDATE: Setting KeepAlive to false doesn't help it. Also, it's not a timeout issue, I'm getting the error quite fast.
Any idea what could be going on?
Thanks!
I'd try updating your request settings like UserAgent or Accept. It's possible they're serving images dynamically and reject requests that don't look like normal traffic.