Can't get transports in SignalR - asp.net-mvc

When I run $.connection.hub.start() I get these errors from "resources" (I traced it).
These are the errors i'm getting
errorOnNegotiate -> "Error during negotiation request.".
errorParsingNegotiateResponse -> "Error parsing negotiate response.".
errorSourceError -> "Error raised by EventSource".
eventSourceFailedToConnect -> "EventSource failed to connect.".
longPollFailed -> "Long polling request failed.".
noConnectionTransport -> "Connection is in an invalid state, there is
no transport active.". nojQuery -> "jQuery was not found. Please
ensure jQuery is referenced before the SignalR client JavaScript
file.". noTransportOnInit -> "No transport could be initialized
successfully. Try specifying a different transport or none at all for
auto initialization.".

Part of the error is this : "jQuery was not found. Please ensure jQuery is referenced before the SignalR client JavaScript file.""
you need to add jQuery reference this can be done like so (Please note that in this sample the signalR version is 2.0.2 you need to add the correct reference to the version you are using):
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-1.6.4.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.0.2.min.js"></script>

It looks like you've pasted the contents of the resources object within signalR._.error(). That object contains a list of possible errors, not the error your're getting. For example, here it's being used to get the error message when the negotiation response couldn't be parsed:
try {
res = connection._parseResponse(result);
} catch (error) {
onFailed(signalR._.error(resources.errorParsingNegotiateResponse, error), connection);
return;
}
To see which error you're actually getting, look at what the code is trying to utilize from this object.

Related

Serverless - Change the content before deploy

I'm using Serverless for working with our aws lambda / appsync.
For Error Handling, we are keep erro code with message in a json file. The Codes will be unique. Something like this:
//error-code.json
{
"1"": { code: 1, message: "Invalid User Input"},
"2"": { code: 2, message: "Invalid Input"},
//... so on
}
This wil lbe deploy as layer and all the lambda will use it. Issue is we cannot use it in the resolve template. There are some of the resolver will be only template file. These template files cannot access the json file nor can access the layer. How can I use the error-code.json here?
Solution 1:
Manually write the error code in templates and make sure there are alway unique. Something like this:
#set(#errorInfo = {
"erroCode": "1",
"errorMessage": "Invalid Input"
})
$util.error("Invalid Input", "errorType", $ctx.arguments,#errorInfo)
Rejected: Becasue we have to manually check everytime for the unique of error code. In case of lot of template file, we cannot rely on it.
Solution 2:
Create a table with error code (unique) and error message. Use this table to send error from template.
Rejected: Because we use multiple app sync instance and they all connect to dirferent database. So we have to make this table in all database, and thus unique across the app-sync is not maintained.
Solution 3:
Write the placeholder in vtl where we want to send the error. Before Deploy, replace the placeholder with the actual code using pre-hook script, but not in the actual vtl file but in the generated package that serverless deploy. Does Serverless even such thing?
if your errors are all static, there is one more option for consideration.
You create one more file that holds all errors defined in Velocity.
$util.qr( $ctx.stash.put("errors", {}) ) $util.qr(
$util.qr( $ctx.stash.errors.put("ONE", { "code": 1, "message": "Invalid User
Input"} )
...
$util.qr( $ctx.stash.errors.put("TWENTY", { "code": 20, "message": "20th error description"} )
For every velocity resolver that throws errors, you inject pre-defined errors at the beginning of its request mapping's file. Whenever you want to throw an error, it's done by retrieving a pre-defined error from $ctx.stash
$util.error ( $ctx.stash.errors.ONE.message, $ctx.stash.errors.ONE.code )
The error file is generated from error-code.json, or manually typed again for simplicity. $ctx.stash is used because stash is accessible from everywhere in a resolver, including pipeline ones.

datatables.net: Error handling for server side processing

I've setup datatables.net with server side processing on a MVC application using the DataTables.Aspnet.Core & DataTables.AspNet.WebApi2 nugets. All works well and the data gets loaded and displayed fine.
If there is an issue on the server side I catch the exception and return a result containing my custom error message:
// IDataTablesRequest tableRequest
return new DataTablesJsonResult(Response.Create(tableRequest, "my custom error message"), Request);
On the client side I've registered to the error event as well:
$.fn.dataTable.ext.errMode = 'none';
this.$dataTable.on('error.dt', this.onDataTableError.bind(this));
This also works fine, I can parse the response and check for my custom message.
Now the issue: After handling the error I always get the dreaded Uncaught TypeError: Cannot read property 'length' of undefined I assume this is the case because I don't send any data to the client?
How can I prevent this error?
I could not manage to fix this on the server side by adding an empty dataset as this would not be passed with the json.
What I ended up doing is ensuring there is always a data array on the client side:
// register to ajax request event
this.$dataTable.on('xhr.dt', this.afterAjax.bind(this));
// set empty array to make sure we have no issue
// with null references on data.length for loop
afterAjax(event: JQueryEventObject, settings: any, payload: any, response: any): void {
payload.data = payload.data || [];
}

Getting an Error "image source error at React Native"

I'm fetching data from web API service from react native ios project, and I got this message
The RCTURLRequestHandlers RCTDataRequestHandler: 0x7a11c0e0 and RCTImageStoreManager: 0x7a6c46a0 both reported that they can handle the request NSURLRequest: 0x7a28bb10 { URL: %250D%250A%250D%250Ahttps://webApiURL/post1.png }, and have equal priority (0). This could result in non-deterministic behavior.
How can I resolve this issue?
I assigned the Image source this way
<Image source={{uri: post.ImagePath}} />
And when I tried to remove "uri"
<Image source={post.ImagePath} />
I got a warning message
"Warning: Failed propType: Invalid prop source supplied to Image. Check the render method of StaticRenderer."
It seems like the %250D%250A%250D%250Apart of the post.ImagePath should not be there.
Could you show the contents of your post object?

Xamarin PCL that makes requests to REST service and returns models

So as recommended I'd like to use RestSharp to handle REST web service. I am developing iOS and Android application and I would love to make PCL that makes requests to the service and just returns parsed results (eg. array of User objects).
So how do I get RestSharp in my PCL, tried NuGet, components are not for PCLs and seriously bad would be to just download source files and copy them in the project, I want to keep some dependency management in place.
What is the best practice? Am I looking at this problem at wrong angle?
RestSharp doesn't support PCLs. I'd suggest checking out PortableRest, or just using a combination of HttpClient and Json.NET.
I use dependency injection so I can support non-PCL JSON parsers. I also plan to give the native HttpClient wrappers from the component store a try. By using non-PCL code you will gain quite a lot in performance compared to Json.NET etc.
Link to source code
Text library has serializer interfaces, Web has the IRestClient.
Modern HTTP Client from the component store.
Below modifications worked for me and will be glad if it works out to you.
Try using modernhttpclient in your PCL. And inAndroid project ensure you have the below packages.
Microsoft.Bcl.Build
Microsoft.Bcl
Microsoft.Net.Http
modernhttpclient
Along with that in application manifest under required permissions give permissions to the below.
Access_Network_State
Access_wifi_state
Internet
Ideally when you try to add Microsoft.Bcl into your Android project targettting monoandroid it will throw out error, so try to add the nuget refrence in the above order.
I developed a really simple REST client to perform Http requests easily. You can check it on my Github repo. The API is really simple:
await new Request<T>()
.SetHttpMethod(HttpMethod.[Post|Put|Get|Delete].Method) //Obligatory
.SetEndpoint("http://www.yourserver.com/profilepic/") //Obligatory
.SetJsonPayload(someJsonObject) //Optional if you're using Get or Delete, Obligatory if you're using Put or Post
.OnSuccess((serverResponse) => {
//Optional action triggered when you have a succesful 200 response from the server
//serverResponse is of type T
})
.OnNoInternetConnection(() =>
{
// Optional action triggered when you try to make a request without internet connetion
})
.OnRequestStarted(() =>
{
// Optional action triggered always as soon as we start making the request i.e. very useful when
// We want to start an UI related action such as showing a ProgressBar or a Spinner.
})
.OnRequestCompleted(() =>
{
// Optional action triggered always when a request finishes, no matter if it finished successufully or
// It failed. It's useful for when you need to finish some UI related action such as hiding a ProgressBar or
// a Spinner.
})
.OnError((exception) =>
{
// Optional action triggered always when something went wrong it can be caused by a server-side error, for
// example a internal server error or for something in the callbacks, for example a NullPointerException.
})
.OnHttpError((httpErrorStatus) =>
{
// Optional action triggered when something when sending a request, for example, the server returned a internal
// server error, a bad request error, an unauthorize error, etc. The httpErrorStatus variable is the error code.
})
.OnBadRequest(() =>
{
// Optional action triggered when the server returned a bad request error.
})
.OnUnauthorize(() =>
{
// Optional action triggered when the server returned an unauthorize error.
})
.OnInternalServerError(() =>
{
// Optional action triggered when the server returned an internal server error.
})
//AND THERE'S A LOT MORE OF CALLBACKS THAT YOU CAN HOOK OF, CHECK THE REQUEST CLASS TO MORE INFO.
.Start();

failed to upgrade a token

I was testing Zend Gdata 1.10.1 in my localhost.
I downloaded Zend Gdate from this link:
http://framework.zend.com/download/webservices
Inside the Zend Gdata zip file, there was a folder called demos.
I extracted it and used the YouTudeVideoApp to upload a sample video to Youtube.
But every time after I logged into Youtube, before it redirected me to my localhost,
I received a warning message like this warning message:
localhost: This website is registered
with Google to make authorization
requests, but has not been configured
to send requests securely. We
recommend that you continue the
process only if you trust the
following destination:
localhost:8080/youtube/operations.php
So I googled on how to resolve the problem of getting this warning message when
I saw some people suggesed changing the value of $secure to True in operation.php.
Here is the script mentioned:
function generateAuthSubRequestLink($nextUrl = null)
{
$scope = 'http://gdata.youtube.com';
$secure = true;
$session = true;
if (!$nextUrl) {
generateUrlInformation();
$nextUrl = $_SESSION['operationsUrl'];
}
$url = Zend_Gdata_AuthSub::getAuthSubTokenUri($nextUrl, $scope, $secure, $session);
echo '<a href="' . $url
. '"><strong>Click here to authenticate with YouTube</strong></a>';
}
After I altered the value of $secure to True,
I found that the warning message changed to this:
localhost: Registered, secure. This
website is registered with Google to
make authorization requests
The new warning message is somehow shorter and looks better than the previous warning message.
But once I pressed the Allow Access button, it turned out to be this:
ERROR - Token upgrade for
CI3M6_Q3EOGkxoL-_____wEYjffToQQ failed
: Token upgrade failed. Reason:
Invalid AuthSub header. Error 401
ERROR - Unknown search type - ''
I don't know why this happened.
Could you help me solve the problem please?
edit your php.ini file and enable the openssl extensions
extension=php_openssl.dll
restart the httpd or IIS server

Resources