Added exception handling to authorization process

This commit is contained in:
Justin Foell
2020-04-24 10:25:11 -05:00
parent 335ea74d07
commit 2fc9436b09
3 changed files with 12 additions and 6 deletions
+2
View File
@@ -105,6 +105,8 @@ On the WP-Strava settings page you cannot currently remove and add another athle
= 2.3.0 =
Renamed LatestActivities classes to ActivitiesList.
Added exception handling to authorization process.
= 2.2.0 =
Added rudimentary gutenberg block for single Activity.
+5 -1
View File
@@ -118,7 +118,11 @@ abstract class WPStrava_Auth {
$data = $this->add_initial_params( $data );
$strava_info = $this->token_request( $data );
try {
$strava_info = $this->token_request( $data );
} catch ( WPStrava_Exception $e ) {
wp_die( $e->to_html() ); // phpcs:ignore -- Debug only.
}
if ( isset( $strava_info->access_token ) ) {
$settings->add_id( $client_id );
+5 -5
View File
@@ -1,10 +1,8 @@
<?php
<?php // phpcs:disable Generic.Files.OneClassPerFile.MultipleFound, Generic.Classes.DuplicateClassName.Found, Generic.Files.OneObjectStructurePerFile.MultipleFound
/**
* WPStrava Exception(s).
*/
// phpcs:disable Generic.Files.OneClassPerFile.MultipleFound, Generic.Classes.DuplicateClassName.Found
/*
* PHP 5.2 Nonsense
* @see http://php.net/manual/en/exception.getprevious.php#106020
@@ -30,6 +28,9 @@ if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
/*
* Exception class for error handling/display.
*
* For creation use `new WPStrava_Exception()` or `WPStrava_Exception::from_wp_error( $error )`.
* For display use $e->to_html(), echo/(s)printf $e, or strval( $e ).
*/
class WPStrava_Exception extends WPStrava_Abstract_Exception {
@@ -80,7 +81,7 @@ class WPStrava_Exception extends WPStrava_Abstract_Exception {
* @author Justin Foell <justin@foell.org>
* @since 1.6.0
*/
public function get_formatted_message( $exception ) {
private function get_formatted_message( $exception ) {
$code = $exception->getCode();
if ( $exception->getPrevious() ) {
@@ -100,4 +101,3 @@ class WPStrava_Exception extends WPStrava_Abstract_Exception {
return sprintf( __( 'WP Strava ERROR %1$s', 'wp-strava' ), $exception->getMessage() );
}
}
// phpcs:enable