Skip to content

Commit

Permalink
Added documentation for error response
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Nov 28, 2016
1 parent bed3f77 commit b41d1bb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ This produces.

A full example of paging is provided below.


### Exceptions

The library will raise **CloudFlareAPIError** when the API call fails.
Expand Down Expand Up @@ -331,6 +330,38 @@ import CloudFlare.exceptions
...
```

### Exception examples

Here's examples using the CLI command cli4 of the responses passed back in exceptions.

First a simple get with a clean (non-error) response.

```
$ cli4 /zones/:example.com/dns_records | jq -c '.[]|{"name":.name,"type":.type,"content":.content}'
{"name":"example.com","type":"MX","content":"something.example.com"}
{"name":"something.example.com","type":"A","content":"10.10.10.10"}
$
```

Next a simple/single error response.
This is simulated by providing incorrect authentication information.

```
$ CF_API_EMAIL='someone@example.com' cli4 /zones/
cli4: /zones - 9103 Unknown X-Auth-Key or X-Auth-Email
$
```

Finally, a command that provides more than one error response.
This is simulated by passing an invalid IPv4 address to a DNS record creation.

```
$ cli4 --post name='foo' type=A content="1" /zones/:example.com/dns_records
cli4: /zones/:mahtin.net/dns_records - 9005 Content for A record is invalid. Must be a valid IPv4 address
cli4: /zones/:mahtin.net/dns_records - 1004 DNS Validation Error
$
```

## Included example code

The [examples](https://github.com/cloudflare/python-cloudflare/tree/master/examples) folder contains many examples in both simple and verbose formats.
Expand Down
34 changes: 34 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,40 @@ the additional error.
exit('api error: %d %s' % (e, e))
...
Exception examples
~~~~~~~~~~~~~~~~~~

Here's examples using the CLI command cli4 of the responses passed back
in exceptions.

First a simple get with a clean (non-error) response.

::

$ cli4 /zones/:example.com/dns_records | jq -c '.[]|{"name":.name,"type":.type,"content":.content}'
{"name":"example.com","type":"MX","content":"something.example.com"}
{"name":"something.example.com","type":"A","content":"10.10.10.10"}
$

Next a simple/single error response. This is simulated by providing
incorrect authentication information.

::

$ CF_API_EMAIL='someone@example.com' cli4 /zones/
cli4: /zones - 9103 Unknown X-Auth-Key or X-Auth-Email
$

Finally, a command that provides more than one error response. This is
simulated by passing an invalid IPv4 address to a DNS record creation.

::

$ cli4 --post name='foo' type=A content="1" /zones/:example.com/dns_records
cli4: /zones/:mahtin.net/dns_records - 9005 Content for A record is invalid. Must be a valid IPv4 address
cli4: /zones/:mahtin.net/dns_records - 1004 DNS Validation Error
$

Included example code
---------------------

Expand Down

0 comments on commit b41d1bb

Please sign in to comment.