My Cloud Code below was working fine until recently. Now I'm getting an error message (see below) but don't know why. My guess is Parse updated some of their API, but I do not know for sure. Also, I'm not a JavaScript person and therefore are hoping for some insight. Does somebody have a hint for me?
Parse.Cloud.define("setUserAnswersForQuestionIds", function(request, response) {
//the following line creates the error
var userId = request.user.get("userId"),
endpointURL = constants.apiURL2 + userId + "/preferences";
...
Here is the error message
{
"code": 141,
"error": "TypeError: Cannot call method 'get' of null\n at vivanda_api.js:241:29"
}
You're sending the request from a non-active user session: i.e. no one is logged in, thus request.user is null.
Related
Trying to implement ApplePay for Web using ApplePay.js. If the user enters an invalid shipping address, I'd like to highlight an error on the paysheet so that the user has a chance to correct the issue. I see there is an ApplePayError class here: https://developer.apple.com/documentation/applepayjs/applepayerror, however I have no idea how to utilize this class. I've tried this with no luck:
var err = new ApplePayError("shippingContactInvalid", "postalAddress", "Address is invalid");
Is this even right? It doesn't display any error on the paysheet so I think it's wrong but I don't know how to do this and I can't seem to find any information about it's usage. Can someone point me in the right direction here?
Ensure version 3 of Apple Pay js api is being used to create the ApplePaySession.
Then pass a result object with status and errors into a 'completion' method:
var err = new ApplePayError("shippingContactInvalid", "postalAddress", "Address is invalid");
session.completePayment({
status: ApplePaySession.STATUS_FAILURE,
errors: [ err ]
});
The default ASP.NET Web Api Core behaviour for unauthorized request is to send 401/403 error with empty content. I'd like to change it by specifying some kind of Json response specifying the error.
But I struggle to find a right place where I can introduce these changes. Official documentation is of no help (read it all). I had a guess that may be I could catch UnathorizedException in my exception filter / middleware but it didn't work out (I guess it gets handled at authorization level or even not thrown at all).
So my question is how can I customize response behavior in case of unauthorized request.
With .Net Core 3 (or may be earlier as well) you can write a middleware to check if the context.Response has a status of 40x and then return a custom object. Below is roughly how I did it:
if (context.Response.StatusCode == (int)HttpStatusCode.Unauthorized)
{
var result = new MyStandardApiResponseDto
{
Error = new MyErrorDto
{
Title = "Unauthorized",
Messages = new List<string> { "You are not authorized to access the resource. Please login again." },
},
Result = null
};
await context.Response.WriteAsync(JsonConvert.SerializeObject(result));
}
I am trying to get a Reservation object which contains a pointer to Restaurant.
In Parse Cloud code, i am able to get the restaurants objects associated with Reservations via query.include('Restaurant') in log just before response.success. However, the Restaurants reverted back to pointer when i receive the response on client app.
I tried reverted JSSDK version to 1.4.2 & 1.6.7 as suggested in some answers, but it doesn't work for me.
Parse.Cloud.define('getreservationsforuser', function(request, response) {
var user = request.user
console.log(user)
var query = new Parse.Query('Reservations')
query.equalTo('User', user)
query.include('Restaurant')
query.find({
success : function(results) {
console.log(JSON.stringify(results))
response.success(results)
},
error : function (error) {
response.error(error)
}
})
})
response :
..."restaurant":{"__type":"Pointer",
"className":"Restaurants",
"objectId":"kIIYe7Z0tD"},...
You can't directly send the pointer objects back from cloud code even though you have included it. You need to manually copy the content of that pointer object to a javascript object. Like below:
var restaurant = {}
restaurant["id"] = YOUR_POINTER_OBJECT.id;
restaurant["createdAt"] = YOUR_POINTER_OBJECT.createdAt;
restaurant["custom_field"] = YOUR_POINTER_OBJECT.get("custom_field");
ps: in your code you seem do nothing else other than directly send the response back. I think parse REST api might be a better choice in that case.
It turned out that my code implementation was correct.
I have a datasource with error handler defined as below. In the code I am intentionally causing an error on post and the server is returning 500 plus the json data, but the error event is not being raised on post. It does fire on the read event. See http://www.ageektech.com/simplyfundraising Open your browser debugger, refresh the page, click edit change any value, click update. Need help figuring out why the error event is not triggered.
Thanks,
Dan
schema : {
model : myModel,
data : "__ENTITIES",
errors: function(e) {
debugger;
// var xhr = e.xhr;
// var statusCode = e.status;
// var errorThrown = e.errorThrown;
//alert(JSON.parse(e.responseText).error.innererror.message);
return e.errors;
}
This is not the way to subscribe to the error event of the DataSource. The schema.errors setting is used for a different purpose.
Schema.errors should contain the name of the JSON field that contains error messages.
e.g.
schema: { errors: "Errors" }
For when you are returning JSON like:
{ "Errors": "Stuff went wrong" }
I tried with this code to post on the wall (Twitter) of a user
if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null)
{
credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"];
credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"];
}
auth = new MvcAuthorizer
{
Credentials = credentials
};
auth.CompleteAuthorization(Request.Url);
if (!auth.IsAuthorized)
{
Uri specialUri = new Uri(Request.Url.ToString());
return auth.BeginAuthorization(specialUri);
}
twitterCtx = new TwitterContext(auth);
twitterCtx.UpdateStatus("Welcome");
Probleme : the first test goes well, I posted on the wall the second test shows this error:
Error while querying Twitter.
someone can help me to solve this problem
Thanks,
LINQ to Twitter throws a TwitterQueryException when detecting an error from Twitter. You can look at the Response property of the TwitterQueryException instance to see the message that Twitter is sending back. Another way to get a complete view of the query and Twitter's response is to use Fiddler2 to view the HTTP traffic and see what Twitter's response is.
In your case, I'm looking at the fact that you said the first post worked, but the second one doesn't. This might be caused by posting a duplicate message, which Twitter doesn't allow. If you look at any of the LINQ to Twitter demos that post a message, you'll notice that they contain a DateTime, which practically guarantees that the text of each message will be different. So, In your case, you could try this:
twitterCtx.UpdateStatus("Welcome - " + DateTime.Now.ToString());
You're welcome to provide more info by posting the contents of the Response property from the TwitterQueryException. Also, for more info, I've begun a FAQ at http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation.