Skip to content

Commit

Permalink
Merge pull request #115 from EasyPost/fix_catch_error_examples
Browse files Browse the repository at this point in the history
fix: catch error examples
  • Loading branch information
Justintime50 authored Nov 28, 2023
2 parents f234e53 + 1f34492 commit fd3cd28
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions official/guides/errors-guide/csharp/catch-error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion official/guides/errors-guide/golang/catch-error.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ func main() {
},
)

fmt.Println(err)
if err, ok := err.(*easypost.APIError); ok {
fmt.Println(err.Code)
}
}
6 changes: 3 additions & 3 deletions official/guides/errors-guide/java/catch-error.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
}
}
4 changes: 2 additions & 2 deletions official/guides/errors-guide/node/catch-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
10 changes: 7 additions & 3 deletions official/guides/errors-guide/php/catch-error.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

try {
\EasyPost\Address::create(array(..., "strict_verify" => true));
catch (\EasyPost\Error $e) {
echo $e->ecode;
\EasyPost\Address::create([
"strict_verify" => true,
]);
} catch (\EasyPost\Exception\Api\ApiException $error) {
echo $error->code;
}
4 changes: 2 additions & 2 deletions official/guides/errors-guide/python/catch-error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

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)
2 changes: 1 addition & 1 deletion official/guides/errors-guide/ruby/catch-error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

begin
Address.create({}, strict_verify: true)
rescue EasyPost::Error => e
rescue EasyPost::Errors::ApiError => e
p e.code
end

0 comments on commit fd3cd28

Please sign in to comment.