From 8a2b8e08033b5146bc4bb0be45590efa1c562eed Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Tue, 28 Nov 2023 15:24:34 -0700 Subject: [PATCH 1/2] fix: catch error examples --- official/guides/errors-guide/csharp/catch-error.cs | 4 ++-- official/guides/errors-guide/golang/catch-error.go | 2 +- official/guides/errors-guide/java/catch-error.java | 6 +++--- official/guides/errors-guide/node/catch-error.js | 4 ++-- official/guides/errors-guide/php/catch-error.php | 10 +++++++--- official/guides/errors-guide/python/catch-error.py | 5 +++-- official/guides/errors-guide/ruby/catch-error.rb | 4 ++-- 7 files changed, 20 insertions(+), 15 deletions(-) diff --git a/official/guides/errors-guide/csharp/catch-error.cs b/official/guides/errors-guide/csharp/catch-error.cs index 0160d939..c68ae8af 100644 --- a/official/guides/errors-guide/csharp/catch-error.cs +++ b/official/guides/errors-guide/csharp/catch-error.cs @@ -8,7 +8,7 @@ } await Address.Create(parameters); } -catch (EasyPost.HttpException e) +catch (EasyPost.Exceptions.API.ApiError error) { - Console.Write(e.Code); // ADDRESS.VERIFY.FAILURE + Console.Write(error.Code); // ADDRESS.VERIFY.FAILURE } diff --git a/official/guides/errors-guide/golang/catch-error.go b/official/guides/errors-guide/golang/catch-error.go index bf2e5763..5f860230 100644 --- a/official/guides/errors-guide/golang/catch-error.go +++ b/official/guides/errors-guide/golang/catch-error.go @@ -20,5 +20,5 @@ func main() { }, ) - fmt.Println(err) + fmt.Println(err.Code) } diff --git a/official/guides/errors-guide/java/catch-error.java b/official/guides/errors-guide/java/catch-error.java index ff386763..9b7abce1 100644 --- a/official/guides/errors-guide/java/catch-error.java +++ b/official/guides/errors-guide/java/catch-error.java @@ -3,7 +3,7 @@ import java.util.HashMap; import com.easypost.EasyPost; -import com.easypost.exception.EasyPostException; +import com.easypost.exception.APIException; public class CatchError { public static void main(String[] args) throws EasyPostException { @@ -15,8 +15,8 @@ public static void main(String[] args) throws EasyPostException { address.put("verify_strict", true); Address.create(address); - } catch (EasyPostException e) { - System.err.println(e.getMessage()); + } catch (APIException error) { + System.err.println(error.getCode()); } } } diff --git a/official/guides/errors-guide/node/catch-error.js b/official/guides/errors-guide/node/catch-error.js index 1ca8ef99..f5165d13 100644 --- a/official/guides/errors-guide/node/catch-error.js +++ b/official/guides/errors-guide/node/catch-error.js @@ -3,6 +3,6 @@ const api = new Easypost('{API_KEY}'); api.Address.save({ strict_verify: true, -}).catch((e) => { - console.log(e); +}).catch((error) => { + console.error(error.code); }); diff --git a/official/guides/errors-guide/php/catch-error.php b/official/guides/errors-guide/php/catch-error.php index e41bd1bf..7893da74 100644 --- a/official/guides/errors-guide/php/catch-error.php +++ b/official/guides/errors-guide/php/catch-error.php @@ -1,5 +1,9 @@ + true)); -catch (\EasyPost\Error $e) { - echo $e->ecode; + \EasyPost\Address::create([ + "strict_verify" => true, + ]); +} catch (\EasyPost\Exception\Api\ApiException $error) { + echo $error->code; } diff --git a/official/guides/errors-guide/python/catch-error.py b/official/guides/errors-guide/python/catch-error.py index 682f2a8b..01e9c441 100644 --- a/official/guides/errors-guide/python/catch-error.py +++ b/official/guides/errors-guide/python/catch-error.py @@ -1,6 +1,7 @@ import easypost + try: easypost.Address.create({"strict_verify": True}) -except easypost.Error as e: - print(e.json_body["code"]) +except easypost.errors.api.ApiError as error: + print(error.code) diff --git a/official/guides/errors-guide/ruby/catch-error.rb b/official/guides/errors-guide/ruby/catch-error.rb index 7498513a..4f4f1d43 100644 --- a/official/guides/errors-guide/ruby/catch-error.rb +++ b/official/guides/errors-guide/ruby/catch-error.rb @@ -2,6 +2,6 @@ begin Address.create({}, strict_verify: true) -rescue EasyPost::Error => e - p e.code +rescue EasyPost::Errors::ApiError => error + p error.code end From 1f34492754f5fcaf2451f7b2e0e2e8de7417992a Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Tue, 28 Nov 2023 15:31:55 -0700 Subject: [PATCH 2/2] fix: lint --- official/guides/errors-guide/golang/catch-error.go | 4 +++- official/guides/errors-guide/python/catch-error.py | 1 - official/guides/errors-guide/ruby/catch-error.rb | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/official/guides/errors-guide/golang/catch-error.go b/official/guides/errors-guide/golang/catch-error.go index 5f860230..51681b29 100644 --- a/official/guides/errors-guide/golang/catch-error.go +++ b/official/guides/errors-guide/golang/catch-error.go @@ -20,5 +20,7 @@ func main() { }, ) - fmt.Println(err.Code) + if err, ok := err.(*easypost.APIError); ok { + fmt.Println(err.Code) + } } diff --git a/official/guides/errors-guide/python/catch-error.py b/official/guides/errors-guide/python/catch-error.py index 01e9c441..f4f2bba3 100644 --- a/official/guides/errors-guide/python/catch-error.py +++ b/official/guides/errors-guide/python/catch-error.py @@ -1,6 +1,5 @@ import easypost - try: easypost.Address.create({"strict_verify": True}) except easypost.errors.api.ApiError as error: diff --git a/official/guides/errors-guide/ruby/catch-error.rb b/official/guides/errors-guide/ruby/catch-error.rb index 4f4f1d43..efcd5c68 100644 --- a/official/guides/errors-guide/ruby/catch-error.rb +++ b/official/guides/errors-guide/ruby/catch-error.rb @@ -2,6 +2,6 @@ begin Address.create({}, strict_verify: true) -rescue EasyPost::Errors::ApiError => error - p error.code +rescue EasyPost::Errors::ApiError => e + p e.code end