failed to register error on push notification mobilefirst 8.0 - angularjs

In my application I use MobileFirst Platform push notification,
MFPPush.registerDevice(
function(successResponse) {
alert("Successfully registered");
},
function(failureResponse) {
alert("Failed to register"+failureResponse);
}
);
I get the following error,
"Failed to register
com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushException
:Response:status=400,Text:"Invalid request body JSON mapping
failed",Error Message:Bad Request"

Have you created a scope "push.mobileclient" ? If not please got to Security and create above scope . After that add above block inside success callback of WLAuthorizationManager.obtainAccessToken("push.mobileclient").then().

Related

PubNub AngularJS error in push config: 'Pubnub.push.addChannels' is undefined

Using PubNub and trying to setup push for ios (apns) per their docs.
The following generates the error:
var initPubnubPush = function(token) {
Pubnub.push.addChannels(
{
channels: ['my_first_channel'],
device: token,
pushGateway: 'apns' // apns, gcm, mpns
},
function(status) {
if (status.error) {
console.log("operation failed w/ error:", status);
} else {
console.log("operation done!")
}
}
);
}
I have their publish/subscribe working on the channel my_first_channel and push should work when the app is in background. The token is valid and is returned from
pushNotification.register(
tokenHandler,
errorHandler,
{
'badge':'true',
'sound':'true',
'alert':'true',
'ecb':'onNotificationAPN'
}
);
function tokenHandler(token) {
// This is a device token you will need later to send a push
// Store this to PubNub to make your life easier :-)
initPubnubPush(token);
}
The complete error in Safari console while running on real iPhone device:
Error in Success callbackId: PushPlugin63370093 : TypeError:
Pubnub.push.addChannels is not a function.
(In 'Pubnub.push.addChannels', 'Pubnub.push.addChannels' is undefined)
Can't find anything in google for this error.
Turns out there is a bug in the PubNub Angular library and that method push.addChannels is not properly delegated.

Custom remote validator error message

With a custom remote validator, how are you supposed to get rid of the error messages?
Using data-parsley-remote-validator='mycustom' on the field will give you an error in the console 'undefined async validator' unless the validator is added on DOM ready i.e not inside another function. However, if it is added on DOM ready, then parsley automatically calls it, which shouldn't happen until submit/change or whatever else you have set.
I can do something like this, but it kind of defeats the object of having parsley call the validator on change:
$('#signUpForm').on('submit', function() {
//add the attribute here to avoid the initial error message
$('#exampleInputEmail1').attr('data-parsley-remote-validator', 'validateEmail');
//then add the custom validator
$('#exampleInputEmail1').parsley()
.addAsyncValidator('validateEmail', function (xhr) {
if(xhr.status == '200') {
return 200;
}
// return the error message if email is taken
else if(xhr.status == '404') {
response = '<ul class="errorlist"><li>That email has already been taken, please try another</li></ul>'
$('#errorResponse').html(response);
}
}, '/api/v1/email/available', { "type": "POST", "dataType": "json", "data": data }
);
});
For those who came here for custom remote validator error message in Parsley.js,
You can add data-parsley-remote-message to the element,
<input type="text" data-parsley-remote-validator="my_remote_validator" data-parsley-remote-message="Custom error message only for remote validation on this element" >
Tested with Parsley.js - Version 2.3.11
Your asynch validator is not supposed to set an error message itself, it should simply return if the value validates or not. The error messages are added with a different API and/or specified as data attributes, check the doc.

Twilio & NodeJS: can't find and delete Media instances/resources

I'm using Twilio's NodeJS module & API to send out MMS messages with images attached (from a remote URL), and I want to delete the Media instances that get created on Twilio servers as soon as I send out the messages.
My messages send out correctly, and in the callback, I'm trying to 1) list media instances for the current message, then 2) loop through those instances and delete. The problem is that the mediaList array that comes back from the API for a current message is always empty.
Here's my code:
twilio_client.messages.create({
body: "Thanks for taking a photo. Here it is!",
to: req.query.From,
from: TWILIO_SHORTCODE,
mediaUrl: photo_URL,
statusCallback: STATUS_CALLBACK_URL
}, function(error, message) {
if (!error) {
twilio_client.messages(message.sid).media.list(function(err, data) {
console.log(data);
// The correct object comes back as 'data' here per the API
// but the mediaList array is empty
}
console.log('Message sent via Twilio.');
res.status(200).send('');
} else {
console.log('Could not send message via Twilio: ');
console.log(error);
res.status(500).send('');
}
});
So, it turns out that trying to get the media list at the point I was trying to doesn't work because the media instances didn't exist yet.
I have a separate little app running at the statusCallback (I supply a URL via a constant in the code above, STATUS_CALLBACK_URL), that until now, just checked to see if a message I tried to MMS to a user wasn't handled properly by Twilio, and alerted the user to a problem via SMS. So, I added a check in that same app to see if the message was actually 'sent' to the user, and then checked for and deleted the media instance(s) associated with the message at that point, and it works fine. Here's my code:
// issue message to user if there's a problem with Twilio getting the photo
if (req.body.SmsStatus === 'undelivered' || req.body.SmsStatus === 'failed') {
twilio_client.messages.create({
body: "We're sorry, but we couldn't process your photo. Please try again.",
to: req.body.To,
from: TWILIO_SHORTCODE
}, function(error, message) {
if (!error) {
console.log('Processing error message sent via Twilio.');
res.send(200,'');
} else {
console.log('Could not send processing error message via Twilio: ' + error);
res.send(500);
}
});
}
// delete media instance from Twilio servers
if (req.body.SmsStatus === 'sent') {
twilio_client.messages(req.body.MessageSid).media.list(function(err, data) {
if (data.media_list.length > 0) {
data.media_list.forEach(function(mediaElement) {
twilio_client.media(mediaElement.sid).delete;
console.log("Twilio media instance deleted");
});
}
});
}

angular ngressource issue TypeError: Cannot read property 'get' of undefined

I'm new to angular and I'm trying to to create a service to register and login users using a spring rest controller, below is the Angular code to retrive Json data
.factory('accountService', function($resource) {
var service = {};
service.register = function(account, success, failure) {
var Account = $resource("/mywebapp/rest/account");
Account.save({}, account, success, failure);
};
service.userExists = function(account, success, failure) {
var Account = $resource("/mywebapp/rest/account");
var data = account.get({email:'email'}, function() {
var accounts = data.accounts;
if(accounts.length !== 0) {
success(accounts[0]);
} else {
failure();
}
},
failure);
};
return service;
})
the problem is that i'm getting two type of error message in chrome and FireFox when trying to connect (service.userExists):
TypeError: Cannot read property 'get' of undefined
at Object.service.userExists (http://localhost:8080/mywebapp/resources/js/account.js:42:27)
at h.$scope.login (http://localhost:8080/mywebapp/resources/js/account.js:56:24)
at http://localhost:8080/mywebapp/resources/lib/angular/angular.js:178:68
at f (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:195:177)
at h.$eval (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:113:32)
at h.$apply (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:113:310)
at HTMLFormElement.<anonymous> (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:195:229)
at http://localhost:8080/mywebapp/resources/lib/angular/angular.js:31:225
at r (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:7:290)
at HTMLFormElement.c (http://localhost:8080/mywebapp/resources/lib/angular/angular.js:31:207)
and in firefox:
"Error: account is undefined
service.userExists#http://localhost:8080/mywebapp/resources/js/account.js:42:13
$scope.login#http://localhost:8080/mywebapp/resources/js/account.js:56:1
gb.prototype.functionCall/<#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:178:66
jc[c]</<.compile/</</f#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:195:177
Yd/this.$get</h.prototype.$eval#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:113:28
Yd/this.$get</h.prototype.$apply#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:113:305
jc[c]</<.compile/</<#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:195:227
ne/c/<#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:31:223
r#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:7:288
ne/c#http://localhost:8080/mywebapp/resources/lib/angular/angular.js:31:207
i'm also getting this error when trying to register a new account:
[HTTP/1.1 415 Type de Support Non Supporté 98ms]
Would you please help me.
ng-resource seems to never receive the account parameter which means the get request is not returning the account. Check the network tools to see what the userExists request is returning from the server.
The message your are receiving for the register could be a hint, I would say it means the API doesn't support your type of client, maybe you're using an old browser or a the server API is very old.

Global error handling in marionette.js

The UI should have a global error handler that shows a popup message whenever an error is received through the API. I'm trying but I'm not getting, I did not find any example too. This should be done Marionette.js. Please help
I got a json file:
{
"errorcodes": [{
"message": "Invalid Email/Password Combination",
"reason": "com.catt.exceptions.catttCustomerPreferencesException: Invalid Email/Password Combination\r\n\tat com.catt.v1.controller.CustomersController.customerLogin(CustomersController.java:303)\r\n\tat sun.reflect.GeneratedMethodAccessor1008.invoke(Unknown Source)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:606)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerM...",
"type": "tCustomerPreferencesError"
}]
}
You can use $.ajaxError to listen for any error happening in $.ajax.
From there, you can make make a Marionnette Application (for example), handle the error, and display an alert
var App = new Marionette.Application();
App.vent.on('error', function(event, jqxhr){
alert(jqxhr.responseText);
});
$(document).ajaxError(function(event, jqxhr, settings, thrownError){
App.vent.trigger('error', event, jqxhr, settings, thrownError);
});
Fiddle Here : http://jsfiddle.net/8ff4n9ut/

Categories

Resources