Plugin Directory

Changeset 758637


Ignore:
Timestamp:
08/19/2013 05:58:35 PM (13 years ago)
Author:
bit.ly
Message:

fixing error messages

Location:
bitly/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • bitly/trunk/bitly.php

    r751675 r758637  
    33Plugin Name: Bitly Official WordPress Plug-in
    44Description: A plugin that replaces shared links with Bitly short urls and gives you the option of placing a widget on your site that shows your popular or most recent bitmarks, or the top results from a search of all currently popular bitly links.  Please visit the plug-in settings page to authorize your Bitly account.  For the widget, please find 'Bitly Bitmarks' under the Available Widgets area.
    5 Version: 1.0
     5Version: 1.0.1
    66Author: Bitly
    77*/
     
    370370    if ( $bitly->hasToken() )
    371371    {
    372         $info = $bitly->userInfo();
    373         error_log("Check if the token is valid on bitly", 0);
    374         if ( isset($info['login']) )
    375         {
    376             $validKey = true;
    377         }
    378         else
    379         {
    380             $validKey = false;
     372        $bitlyError = null;
     373        try {
     374            error_log("Check if the token is valid on bitly", 0);
     375            $info = $bitly->userInfo();
     376            $validKey = true;
     377            } catch (BitlyServiceError $e) {
     378            $validKey = false;
     379            switch ($e->getMessage()) {
     380                case 'MISSING_ARG_ACCESS_TOKEN':
     381                    $bitlyError = 'Please supply an access token.';
     382                    break;
     383                case 'INVALID_ACCESS_TOKEN':
     384                    $bitlyError = '<strong>Invalid access token.</strong> Please verify that you have entered your Bitly Oauth token correctly.';
     385                    break;
     386                default:
     387                    $error = $e->getMessage();
     388                    $errno = $e->getCode();
     389                    if ( !$error )
     390                        $error = 'An unknown error occurred.';
     391                    $bitlyError = "$error (Errno $errno)";
     392            }
    381393        }
    382394    }
     
    408420                    <th><label for="bitly_settings-oauthToken"><?php _e( 'OAuth Token', 'bitly' ); ?></label></th>
    409421                    <td>
    410                         <?php if (isset($validKey) && !$validKey) { echo "<span style='color:red;'><strong>Invalid OAuth Token:</strong> Please verify that you have entered your Bitly OAuth token correctly.</span><br>"; } ?>
     422                        <?php if ($bitlyError !== null) { echo "<span style='color:red;'>$bitlyError</span><br>"; } ?>
    411423                        <input id="bitly_settings-oauthToken" name="bitly_settings[oauthToken]" type="text"
    412424                            value="<?php echo bitly_settings( 'oauthToken' ); ?>" />
  • bitly/trunk/lib/BitlyService.php

    r751675 r758637  
    1919 */
    2020
     21class BitlyServiceError extends Exception {}
     22
    2123class BitlyService {
    2224
     
    282284       
    283285        $response = curl_exec( $handle );
     286
     287        $errno = curl_errno( $handle );
     288        if ( $errno != CURLE_OK )
     289            throw new BitlyServiceError(curl_error( $handle ), $errno);
    284290       
    285291        curl_close( $handle );
     
    290296        {
    291297            $response = @json_decode( $response, true );
     298            if ( $response === null )
     299                throw new BitlyServiceError('JSON could not be decoded', -1);
    292300           
    293301            if ( 200 == $response['status_code'] && 'OK' == $response['status_txt'] )
    294302                return $response;
     303            else
     304                throw new BitlyServiceError($response['status_txt'], $response['status_code']);
    295305               
    296306        }
  • bitly/trunk/readme.txt

    r751675 r758637  
    55Requires at least: 2.8
    66Tested up to: 3.5.1
    7 Stable tag: truck
     7Stable tag: 1.0.1
    88License: GPLv2 or later
    99License URI:
     
    5050= How does the plugin handle previously created posts? =
    5151
    52 Posts that were created prior to installing the plugin will only get a bitly short link when someone actually visits the old post.  This will result in old posts showing up in your public bitly bitmark stream (https://bitly.com/u/BITLYUSERNAME) unless you have set your default bitmark privacy settings to "Private" at https://bitly.com/a/settings/saving
     52Posts that were created prior to installing the plugin will only get a bitly short link when someone actually visits the old post.  This will result in old posts showing up in your public bitly bitmark stream (https://bitly.com/u/BITLYUSERNAME) unless you have set your default bitmark privacy settings to "Private" at https://bitly.com/a/settings/saving
     53
     54== Changelog ==
     55
     56= 1.0.1 =
     57* Clarification for error messages.
     58
     59== Upgrade Notice ==
     60
     61= 1.0.1 =
     62This updated version has error messages that are more specific. Please upgrade if you are getting an 'Invalid Token' error message during setup.
     63 
Note: See TracChangeset for help on using the changeset viewer.