imap_open custom error callback - php

I want to build an authentication system for a website using IMAP. Users should be able to log in with the same credentials as the email account.
Everthing works fine, except if the input data is wrong or didn't match with the email account credentials. If so, there is obviously an error...
imap_open(): Couldn't open stream {domain.com:993/imap/ssl}INBOX
Is there any way to set an custom callback if the imap_open() fails? (Like redirect back with error message, ...)

This is warning level message so you should be able to use error handler, for example:
set_error_handler(function() { /* this will be executed on error */ });
imap_open();
restore_error_handler();
Here is similar question: https://stackoverflow.com/a/1241751/3470670
Here you can find complete documentation about setting custom error handler http://php.net/manual/en/function.set-error-handler.php

Related

catch exceptions from yodlee api

Currently I'm working with the yodlee API. As specified in the documentation the url response may throw InvalidCredentails or UserAccountLocked. I'm using PHP and I get the following response when the username or password is incorrect.
{
Error: [
{
errorDetail: "Invalid Cobrand Credentials"
}
]
}
So to check if the error occurs I want to write some code that checks if errorDetail has a value of Invalid Cobrand Credentials.
So far ok.
But the there may be so many types of errors, and each error name is different. My question is: Can I get the list of these errorDetail values
so that I can make it work without checking if the code is forcebly throwing the errors.
You can just check for the Error index and access it's value for throwing the errors. Something like this should work for you (not tested). From the repo page:
yodleeAPI.getAccounts(accessToken)
.then(function(response) {})
.catch(function(error) {});
Edit:
As far as I could tell there wasn't any exception list. So you're either going to have to go through all the exceptions manually or create a generic error message for users. I would just advice to catch the exception message and use that for the user view(if there isn't any security information in there). You can accomplish that by following the above code.
If you do feel the need to go through every exception yourself I managed to at least get the list of all methods that throw exceptions (search: exception). You'll have to go through it yourself, and parse the error message yourself. But you can find that here

Output error messages from abort on custom error pages in Laravel 5

I've created a custom error template for 401 and 404 errors by following the documentation. They display fine with a fixed error message, but when triggering the error with abort() you can pass in an error message as the second argument. What variable do I need to output to show the message passed through abort? Nothing in the documentation tells you how to output that message on the page and any search for error messages either shows info about the validation function or goes on about logging and triggering errors, but not how to output them on the page.
In your view there will be an $exception variable, that is an instance of HttpException.
You can use $exception->getMessage() method to get your message.

Magento 1.9.1 Forgot Password issue

We are facing a problem with a forgot password on domain.com/customer/account/forgotpassword.
When we enter any wrong email id not associate with any account its works we get this message:
"If there is an account associated with test#test.com you will receive
an email with a link to reset your password."
But when we do with email id associate with account exist its show blank page on domain.com/customer/account/forgotpasswordpost/
I tried solution all side coustmer.xml file mail setting return path yes, but issue is same the same.
You likely have an error breaking your code.
Please check your apache error logs for uncaught errors from Magento
as well as your
root/var/exception.log
and
root/var/system.log
If logs are not enabled, enable them in...
admin/system_config/edit/section/dev/
Debug the following files:
app\code\core\Mage\Customer\controllers\AccountController.php
Use zend debug on: forgotPasswordPostAction line by line on variables such as:
Zend_Debug::dump( $customer );
Zend_Debug::dump( $newResetPasswordLinkToken );
app\code\core\Mage\Customer\Model\Customer.php
changeResetPasswordLinkToken
app\code\core\Mage\Customer\Model\Customer.php
sendPasswordResetConfirmationEmail
app\code\core\Mage\Customer\Model\Customer.php
_sendEmailTemplate
Zend_Debug::dump( $mailer );
Dump out mailer contents on each line to pinpoint which call breaks your code.
As another alternative you can wrap the calls in a try{}catch( Exception $oException ){ Zend_Debug::dump( $oException); }

Fatal error: Uncaught GraphMethodException in base_facebook.php

I am using the Facebook PHP SDK V3.2.3 and have built a web based app which simply gets users albums and pics and displays them on our site after the user authorises themselves.
I have tested the site functionality on different machines on different browsers/networks and everything works as expected from our side. We can authorise as the developers set on the account as well as the test user and authorise and see the pics/albums, problem free.
I submitted the app for review and it was denied - these are the notes returned.
When I click on the Facebook button, I receive the following error message,
" Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in
/home/websitename/public_html/sitedir/src/base_facebook.php
on line 1325."
Has anybody else had this issue? I am am completely at a loss as I can't debug this as I cannot recreate the problem.
It looks like you are trying to access something in your code that you do not have access to, or something that doesn't exist.
You should always wrap your Facebook API code in try...catch statements to catch any issues and fail gracefully.
try {
// some Facebook API call
} catch ( Exception $e ) {
// an error occurred
echo $e->getMessage();
}

Laravel capture whoops app-level exception and post to log with unique ID#

I am looking to make error reporting from an app more friendly to users. I am going to replace the 'Whoops' screen (in production) with a form allowing the user to submit the problem. I am wondering if there is a simple way to add a specific ID# (unique integer) to the stack trace in the error log so that we can easily view specific errors which were generated on production.
The simple way to do this is in app/start/global.php. Under the Application Error Handler you want to log your error, and generate a GUID (or something similar).
App::error(function(Exception $exception, $code)
{
// Generate a unique ID for this error...
$unique_id = uniqid();
// log the error
Log::error(str_repeat('-', 40));
Log::error("Exception for $unique_id");
Log::error($exception);
// return error form
return View::make('whoops_error_form')->with('unique_id', $unique_id);
});
Your whoops_error_form template would have a hidden form somewhere where you will be able to submit the application error. All reports would be logged in app/storage/logs.
By returning the view on App::error, you will disable the other exception handlers (such as Whoops!)

Categories