Title: Error handling
Last modified: August 30, 2016

---

# Error handling

 *  Resolved [boybawang](https://wordpress.org/support/users/boybawang/)
 * (@boybawang)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/error-handling-3/)
 * Hello –
 * I’m a newb with WP plugin development, so take it easy 🙂
 * Is there any problem in storing an API in the DB as cleartext? The problem I’m
   running into (during the development phase) is that I’ve had a couple of warnings
   that display my API call in the browser, which is obviously not good once it 
   goes live.
 * If it’s good practice to store APIs as text, how can I handle the warnings/notices/
   errors/exceptions so that sensitive data is not displayed in the browser?
 * Thanks

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/error-handling-3/#post-6529035)
 * Welcome! I’m not sure I fully understand your question, apologies if my answer
   is to a question of my own imagining and not yours.
 * I’m not sure if your API calls are javascript/jquery or PHP, or something else,
   the answer changes by language. Javascript/jquery is sent out to the client so
   no sensitive information should be handled this way. So I’m assuming you’re referring
   to PHP.
 * While it’s not a problem storing code in the DB, I don’t see the point. Code 
   contained in a .php file should never be visible to users if the server is properly
   configured. Still, error messages, even without displaying code, is a security
   risk. The display is typically managed in wp-config.php with the `WP_DEBUG` constant.
   Defining it as false should hide all messages from users, provided once again
   if the server is properly configured.
 * If the configuration is not right, there is usually some recourse. The details
   are discussed here: [https://codex.wordpress.org/Editing_wp-config.php#Configure_Error_Logging](https://codex.wordpress.org/Editing_wp-config.php#Configure_Error_Logging)
 *  Thread Starter [boybawang](https://wordpress.org/support/users/boybawang/)
 * (@boybawang)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/error-handling-3/#post-6529103)
 * Thanks for the response, bcworkz!
 * Just to clarify, the API call is in PHP, and when I was referring to the DB, 
   I was referring to storing the API key itself (not the code that calls it).
 * As for controlling the error output via wp-config.php (WP_DEBUG), this would 
   only be feasible if I was the only one using the plugin. If that were the case,
   I would simply change my own settings. However, I do plan on pushing this out
   to the community in the future, so modifying wp-config.php for other WP users
   is not feasible.
 * The problem I’ve seen is that for certain PHP Warnings, it’ll output my API call
   to the browser, which contains the API key. I need to prevent this from displaying.
 * I don’t know much about try/catch for exception handling, but how could this 
   be applied to warnings, notices, errors, etc.?
 * I hope that makes sense.
 * Thanks!
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/error-handling-3/#post-6529121)
 * OK, much clearer now, thank you! I don’t have a real answer for you, but some
   random thoughts.
 * I’m mystified how the API key is displayed in normal PHP error messages. Typically
   only the function name is displayed. In any case it is happening and must stop.
   Perhaps it is from the API output and not PHP? If so, the API is quite poorly
   written IMO.
 * Not an excuse, but the API key shown would not be yours, but that of the installation
   site. (Please say it is so!) It must be hidden from the public, but not the site
   admin.
 * Typically, production servers would have WP_DEBUG as false and output any errors
   to a non-public error file. Alas, this is beyond your control, but to do otherwise
   is really the site admins fault for not protecting their own API key. If the 
   key exposure is from the API, this aspect is moot anyway.
 * Ideally, your code should be completely compliant such that even minor notices
   are not output. I realize compliant now may not be compliant tomorrow. Do your
   best.
 * Exception handling is a must have for anticipated operational errors like missing
   files. Unanticipated errors are impractical to handle this way, but perhaps an
   API error could be handled this way. It would depend on the specifics of the 
   API call.
 *  Thread Starter [boybawang](https://wordpress.org/support/users/boybawang/)
 * (@boybawang)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/error-handling-3/#post-6529125)
 * Hey bcworkz –
 * Thanks for your response. I really appreciate you taking the time to explain!
 * Correct, the API shown would be that of the publisher in charge of the installation
   site. I understand WP_DEBUG, but can’t assume everybody will set this to false
   🙂
 * Personally, I have a security plugin named **Bullet Proof Security** that handles
   this. There’s an option to “display errors” (including warnings, notices, etc.).
   Their recommendation is to set it to OFF, which I did. I’m pretty sure they somehow
   handled this via .htaccess, but don’t know for sure.
 * As for the API call itself, all I’m doing is calling a URL that contains the 
   API key within it. This is where I think the hiccup *could* occur. I then store
   the XML string into an XML object using simplexml_load_string(), but I think 
   that at this point I’m safe if the URL containing the API key was well-formed.
 * Thanks
 *  Thread Starter [boybawang](https://wordpress.org/support/users/boybawang/)
 * (@boybawang)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/error-handling-3/#post-6529169)
 * I’ve solved my problem and decided to post here in case anybody needs it. I used:
 * `set_error_hander()`
 * prior to the warning I wanted to capture, and then used
 * `restore_error_handler()`
 * afterwards.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Error handling’ is closed to new replies.

## Tags

 * [handling](https://wordpress.org/support/topic-tag/handling/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 5 replies
 * 2 participants
 * Last reply from: [boybawang](https://wordpress.org/support/users/boybawang/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/error-handling-3/#post-6529169)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
