Flutter - what causes XMLHttpRequest error - flutter

I would like to know if the 'XMLHttpRequest Error' thrown by http package is always due to missing CORS policy header?
The expection thrown in this instance is of Type ClientException - the only things that I can read is the message (XMLHttpRequest Error) and uri. So how would I know it is because of the above.
I get intermittent(and infrequent) errors in the logs, and the CORS policy header is correctly set on the server.
I want to rule out any other causes of XMLHttpRequest Error. Any ideas?

Related

Sanic CORS Exception handler

I have tried to use Sanic_CORS in exception handler like error 404,
but I received CORS error
Access to XMLHttpRequest at 'http://backend:port/endpoint' from origin 'http://react_app:port' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
There are no problems with valid endpoints.
My error handler
#app.exception(NotFound)
async def ignore_404s(request, exception):
return response.json({'message': "Oops, server error"},
status=404)
How can I implement Sanic_CORS for error handlers? Any ideas?
One option would be to just add the header into your response. Albeit, this is not using the sanic-cors package, but you really do not need it here.
#app.exception(NotFound)
async def ignore_404s(request, exception):
return response.json(
{'message': "Oops, server error"},
status=404,
headers={"Access-Control-Allow-Origin": "*"}
)

HTTP status code for failed serialization

I have a GET /v2/developer/jhUxad8 endpoint which get developer from database and serialize it to json.
What http status code should I return when serialization fail?
https://www.codetinkerer.com/2015/12/04/choosing-an-http-status-code.html
What http status code should I return when serialization fail?
If I'm understanding you correctly, the server understands the request, and is trying to fulfill it, but because of a data problem is unable to do so.
500 Internal Server Error
The 500 (Internal Server Error) status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.

TYPO3 - Deactivating cHash in own extension causes error when accessing record

If I add noCacheHash="1" to link.action I can deactivate cHash:
<f:link.action action="show" pageUid="43" arguments="{record:record.uid}" noCacheHash="1">{record.name}</f:link.action>
/?tx_abc_abc[record]=1&tx_abc_abc[action]=show&tx_abc_abc[controller]=Abc
But when trying to access a record I get the following error:
Uncaught TYPO3 Exception
#1509296606: Failed to fetch error page "domain/index.php?id=72", reason: Client error: `GET domain/index.php?id=72` resulted in a `401 Unauthorized` response: <script>window.location.href='domain/access-denied/';</script><noscript>Error 401 - Access Deni (truncated...)
20 TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::pageErrorHandler("domain/index.php?id=72", "HTTP/1.0 404 Not Found", "Request parameters could not be validated (&cHash empty)")
How can I access the record properly when deactivating cHash?
This is not cause with noCacheHash parameters. I think you set special permission for pageID(43). So, this page is not access for this record.
So, First check this page access permission.

Getting an error while invoking a REST service using Javascript

I have developed a REST Web service to get resources, I am able to access it through Java/Spring Template and even the xml response is coming if I type the URI on browser.
But when I invoke the same URI using XMLHttpRequest in Java script I am getting the below error.
"XMLHttpRequest cannot load URI(actual uri with server name ..etc) . Origin file:// is not allowed by Access-Control-Allow-Origin."
Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101.
My JS code is as below.
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://localhost:8080/rest/apps", false );
xmlHttp.send( null );
Please let me know what would be the problem and help me to resolve this.
Regards,
Sreedhar
here Origin is the local file system, that you're loading the HTML page, that load call via a file:/// . the request is from the same origin. If you're trying to load from somewhere else then you will not get the Error.
Check For this answer

SOAP "error fetching http headers": how do I do suspected solution of disabling keep-alive?

I'm troubleshooting an existing webservice. It previously worked just fine, but now SOAP-based requests to the postgreSQL database result in an "unknown error: Error Fetching http headers" error.
In looking up this problem, I come across the following tip:
When you get errors like: "Fatal error: Uncaught SoapFault exception:
[HTTP] Error Fetching http headers in" after a few (time intensive)
SOAP-Calls, check your webserver-config.
Sometimes the webservers "KeepAlive"-Setting tends to result in this
error. For SOAP-Environments I recommend you to disable KeepAlive.
Hint: It might be tricky to create a dedicated vhost for your
SOAP-Gateways and disable keepalive just for this vhost because for
normal webpages Keepalive is a nice speed-boost.
I haven't been able to figure out exactly how you disable KeepAlive or where this parameter would be set. I've tried grep -i "keepalive" /usr/share/tomcat5/conf/*, result negative.
Perhaps due to the variability of server environments this is a question for my sysadmin, but I do have root privileges.
Thanks for your help, stack!
In your Tomcat's server.xml file, set the maxKeepAliveRequests attribute to 1 on your HTTP connectors to effectively disable keep alive.
For more information:
http://tomcat.apache.org/tomcat-5.5-doc/config/http.html#Standard_Implementation