Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch error examples #115

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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