Skip to content

Commit 45cab54

Browse files
committed
PCBC-788: handle rate/quota limit error codes
Change-Id: I4eb955a209cd056f1581be5c53609490b45c4df2 Reviewed-on: https://review.couchbase.org/c/php-couchbase/+/167024 Tested-by: Build Bot <[email protected]> Reviewed-by: Sergey Avseyev <[email protected]>
1 parent c7f426e commit 45cab54

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

api/couchbase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ public function context(): ?object {}
636636

637637
class RequestCanceledException extends BaseException implements Throwable {}
638638

639+
class RateLimitedException extends BaseException implements Throwable {}
640+
641+
class QuotaLimitedException extends BaseException implements Throwable {}
642+
639643
/**
640644
* Thrown for exceptions that originate from underlying Http operations.
641645
*/

config.m4

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ if test "$PHP_COUCHBASE" != "no"; then
1818
elif test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libcouchbase; then
1919
LIBCOUCHBASE_VERSION=`$PKG_CONFIG libcouchbase --modversion`
2020

21-
if $PKG_CONFIG libcouchbase --atleast-version 3.2.2; then
21+
if $PKG_CONFIG libcouchbase --atleast-version 3.2.4; then
2222
LIBCOUCHBASE_CFLAGS=`$PKG_CONFIG libcouchbase --cflags`
2323
LIBCOUCHBASE_LIBS=`$PKG_CONFIG libcouchbase --libs`
2424
AC_MSG_RESULT(from pkgconfig: version $LIBCOUCHBASE_VERSION found)
2525
else
26-
AC_MSG_ERROR([libcouchbase version $LIBCOUCHBASE_VERSION found, must be upgraded to version >= 3.2.2])
26+
AC_MSG_ERROR([libcouchbase version $LIBCOUCHBASE_VERSION found, must be upgraded to version >= 3.2.4])
2727
fi
2828

2929
dnl fallback on standard directory
@@ -50,14 +50,14 @@ if test "$PHP_COUCHBASE" != "no"; then
5050

5151
dnl found in directory
5252
else
53-
AC_MSG_CHECKING([for libcouchbase version >= 3.2.2])
53+
AC_MSG_CHECKING([for libcouchbase version >= 3.2.4])
5454
LCB_VERSION=$($EGREP "define LCB_VERSION " $LIBCOUCHBASE_DIR/include/libcouchbase/configuration.h | $SED -e 's/[[^0-9x]]//g')
5555
AC_MSG_RESULT([$LCB_VERSION])
5656
if test "x$LCB_VERSION" = "x0x000000"; then
5757
AC_MSG_ERROR([seems like libcouchbase is not installed from official tarball or git clone. Do not use github tags to download releases.])
5858
fi
59-
if test $(printf %d $LCB_VERSION) -lt $(printf %d 0x030202); then
60-
AC_MSG_ERROR([libcouchbase greater or equal to 3.2.2 required])
59+
if test $(printf %d $LCB_VERSION) -lt $(printf %d 0x030204); then
60+
AC_MSG_ERROR([libcouchbase greater or equal to 3.2.4 required])
6161
fi
6262

6363
PHP_ADD_INCLUDE($LIBCOUCHBASE_DIR/include)

exception.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ zend_class_entry *pcbc_keyspace_not_found_exception_ce;
7878
zend_class_entry *pcbc_prepared_statement_failure_exception_ce;
7979
zend_class_entry *pcbc_dml_failure_exception_ce;
8080
zend_class_entry *pcbc_request_canceled_exception_ce;
81+
zend_class_entry *pcbc_rate_limited_exception_ce;
82+
zend_class_entry *pcbc_quota_limited_exception_ce;
8183

8284
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(ai_BaseException_ref, IS_STRING, 1)
8385
ZEND_END_ARG_INFO()
@@ -220,6 +222,12 @@ PHP_MINIT_FUNCTION(CouchbaseException)
220222
INIT_NS_CLASS_ENTRY(ce, "Couchbase", "SubdocumentException", NULL);
221223
pcbc_subdocument_exception_ce = zend_register_internal_class_ex(&ce, pcbc_base_exception_ce);
222224

225+
INIT_NS_CLASS_ENTRY(ce, "Couchbase", "RateLimitedException", NULL);
226+
pcbc_rate_limited_exception_ce = zend_register_internal_class_ex(&ce, pcbc_base_exception_ce);
227+
228+
INIT_NS_CLASS_ENTRY(ce, "Couchbase", "QuotaLimitedException", NULL);
229+
pcbc_quota_limited_exception_ce = zend_register_internal_class_ex(&ce, pcbc_base_exception_ce);
230+
223231
return SUCCESS;
224232
}
225233

@@ -442,6 +450,14 @@ void pcbc_create_lcb_exception(zval *return_value, long code, zend_string *conte
442450
exc_ce = pcbc_dml_failure_exception_ce;
443451
break;
444452

453+
case LCB_ERR_RATE_LIMITED:
454+
exc_ce = pcbc_rate_limited_exception_ce;
455+
break;
456+
457+
case LCB_ERR_QUOTA_LIMITED:
458+
exc_ce = pcbc_quota_limited_exception_ce;
459+
break;
460+
445461
default:
446462
exc_ce = pcbc_base_exception_ce;
447463
break;

0 commit comments

Comments
 (0)