I am using the following code to send email for the logged in user.
await _graphClient.Me.SendMail(email, true).Request().PostAsync();
Initially it was executing be no email was sent. After poking around I figured out that a permission was not set. Unfortunately the try..catch around it was not tripped. My questions is if there is a way of detecting that an error occurred with this call.
Regarding
Unfortunately the try..catch around it was not tripped.
PostAsync() method should throw a ServiceException on error.
For example, in case of missing permissions:
try
{
await graphClient.Users[userId].SendMail(message).Request().PostAsync();
}
catch (Microsoft.Graph.ServiceException e)
{
Console.WriteLine(e.Error);
}
the following error should be printed:
Code: ErrorAccessDenied
Message: Access is denied. Check credentials and try again.
Related
I'm trying to check that Twilio object was properly instantiated, but it doesn't work
I do
try {
$twilioObj = new Client($sid, $token);
}
catch (Exception $e){
echo $e->getMessage();
}
^ Regardless if the tokens are valid or not it never results in an error. I noticed that it always generated an object.. So even if I put some random token, I still get an object back.
What is the best way of catching this?
I did is as per documentation: https://www.twilio.com/docs/libraries/php/usage-guide#exceptions but it doesn't work.
The Twilio Client object doesn't know at the time of instantiation whether the credentials you have provided it are valid or not, so it cannot throw an error at that point.
If the credentials are not valid, the client will throw an error when you use it to make a request to the API. You should catch the error there.
As per the documentation, instantiating a Client without a username or password will throw a ConfigurationException.
I'm using the AWSMobileClient on iOS for authentication and I'm not able to sign in. I'm calling the signin method and all I'm getting is the following error:
The operation couldn’t be completed. (AWSMobileClient.AWSMobileClientError error 13.)
This error is useless to me and I can't find any decent documentation on what this error means. Has anyone seen this? Appreciate your help.
Please take a look at this https://github.com/aws-amplify/aws-sdk-ios/issues/1538#issuecomment-491905913
You can cast the error as AWSMobileClientError and switch on it to exhaust the list of errors.
Alternatively, I've moved over the internal message property over to my app like this:
https://github.com/lawmicha/iOS-User-Authentication-with-Email-Facebook-Google/blob/master/AmplifyUserAuthentication1/Internal/ErrorMapper.swift
extension AWSMobileClientError {
var message: String {
switch self {
case .aliasExists(let message),
.badRequest(let message),
and then I can access the message on error after casting it to AWSMobileClientError from if let error = error as? AWSMobileClientError
You should keep in mind that the alternative method exposes the message which is a developer facing message and not a end-user facing message. Ideally when you need to provide an end-user facing message, you would use first method and map the error case to a specific localized message.
I currently am unable to authorize the SquareReaserSDK with iOS (Swift).
I have a node instance that takes in an access_token.
I then call listLocations()
I provide the first location_id in the body of a CreateMobileAuthorizationCodeRequest()
I then pass the resulting mobile auth code to the client
After successfully retrieving a mobile auth token and providing that to the below, the first time this is called there is no callback. The block if statement never fires.
Redundant calls results in an authorization_already_in_progress error (the if statement is fired).
SQRDReaderSDK.shared.authorize(withCode: mobileAuthToken) { location, error in
if let authError = error {
print("Authorize SquareReaderSDK", authError.localizedDescription)
} else {
print("Authorize SquareReaderSDK", location)
Defaults[.establishment]?.squareMobileAuthToken = mobileAuthToken as! String
}
}
authorize() endpoint reference: https://developer.squareup.com/docs/api/reader/ios/Classes/SQRDReaderSDK.html#/Authorization
Redundant calls results in:
vvvvv SQUARE ERROR vvvvv
ERROR: Something went wrong. Please contact the developer of this application and provide them with this error code: authorization_already_in_progress
DEBUG CODE: authorization_already_in_progress
DEBUG MESSAGE: Authorization is already in progress. Please wait for SQRDReaderSDK.shared.authorize() to complete.
^^^^^ SQUARE ERROR ^^^^^
At any point while trying to authorize the device, I get the following error when trying to present the checkoutController:
Checkout Failed:
This device is not currently authorized to accept payments with Square.
Straight from the documentation, it says that:
PFUser#currentUser() gets the currently logged in user from disk and
returns an instance of it.
This is fine and all, but what if the user logged in # disk isn't a user that's logged in on the server. Lets say the users account has been deleted for whatever reason, or the session is no longer valid due to database modifications. These are currently the problems that I'm facing.
Throughout the tutorials that I've read, I've seen using the following line of code as a way to check if the user is valid, and thus you can skip the login stage of the application:
if let user = PFUser.currentUser() as? Subclass {
// Simulate successful login
}
However, this is posing a problem for me, as the successful login is simulated, but the login was not successful. Here is the error I'm dealing with:
[Error]: invalid session token (Code: 209, Version: 1.12.0)
So the first thing I did was attempt to log the user out, however this fails (I assume because the user wasn't logged in to begin with) and now I'm thrown into application which immediately crashes because the data required by the server isn't there. Here's how I attempted to handle error code 209:
let query = PFQuery(className: "Foo")
query.whereKey("Bar", equalTo: "Foo")
query.findObjectsInBackgroundWithBlock {
(foo, error) -> Void in
if let error = error {
print(error);
if error.code == 209 {
PFUser.logOutInBackgroundWithBlock {
(error) -> Void in
if let error = error {
print("Okay, I'm trapped!");
}
}
}
}
}
The output of this "query" is the following:
[Error]: invalid session token (Code: 209, Version: 1.12.0)
Okay, I'm trapped!
I'm out of ideas over here, and I'm ripping my hair out trying to figure out how to properly validate a user upon application launch. It seems redundant to have to catch error code 209 on every query, but if that's what you have to do, then that's what you have to do.
You can use synchronous logout. So even if error occurs, it doesn't matter. The PFUser session token will be invalidated if the user launches the app again.
Also latest Parse SDK provides PFConstants class, which provides enum for all possible error cases.
kPFErrorInvalidSessionToken = 209.
if (error.code == kPFErrorInvalidSessionToken) {
PFUser.logOut()
//Necessary pop of view controllers after executing the previous code.
}
I am wondering if anyone knows a clean programmatic way of detecting a 401 response with the analytics API. I know the underlying HTTP transport probably has it but when the call is made via Analytics object the only indicator of failure is an IOException (which could indicate an error of any type). If there was some way to get at the JSON response that gets shown in the stack trace you could check there maybe, but right now the only thing I can think of is to parse the e.getMessage() string. Example:
GaData gadata = null;
try {
gaData = analytics.data().ga().get(
"ga:" + profileId,
"2012-06-01",
"2012-06-30",
"ga:visits")
.execute();
} catch (IOException ioe) {
if (ioe.contains("401")) {
System.out.println("A 401 occurred.");
}
}
The reason for isolating this case is because it indicates that the access token has expired, so an alternate solution would be a better way for checking if the access token has expired. If this can be done then the code can make a call using the API key to grant a new access token.
The documentation says that the GoogleJsonResponseException will be thrown. GoogleJsonResponseException.getDetails() returns a GoogleJsonError. The GoogleJsonError.code method will return the error code (in this case the HTTP 401 ERROR).