def raise_from_response(resp):
    """Turn a failed request response into a BackendError.  Handy for
    reflecting HTTP errors from farther back in the call chain.

    Parameters
    ----------
    resp: :class:`requests.Response`

    Raises
    ------
    :class:`apikit.BackendError`
        If `resp.status_code` is equal to or greater than 400.
    """
    if resp.status_code < 400:
        # Request was successful.  Or at least, not a failure.
        return
    raise BackendError(status_code=resp.status_code,
                       reason=resp.reason,
                       content=resp.text)