Skip to content

Commit 07deeed

Browse files
committed
Merge pull request facebookarchive#106 from gfosco/error_code
Added validation and test for non-int error_code defaulting to 0.
2 parents 6e194a9 + 9c69b9c commit 07deeed

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/base_facebook.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ class FacebookApiException extends Exception
4242
public function __construct($result) {
4343
$this->result = $result;
4444

45-
$code = isset($result['error_code']) ? $result['error_code'] : 0;
45+
$code = 0;
46+
if (isset($result['error_code']) && is_int($result['error_code'])) {
47+
$code = $result['error_code'];
48+
}
4649

4750
if (isset($result['error_description'])) {
4851
// OAuth 2.0 Draft 10 style

tests/tests.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,11 @@ public function testExceptionConstructorWithErrorCode() {
13501350
$this->assertEquals($code, $e->getCode());
13511351
}
13521352

1353+
public function testExceptionConstructorWithInvalidErrorCode() {
1354+
$e = new FacebookApiException(array('error_code' => 'not an int'));
1355+
$this->assertEquals(0, $e->getCode());
1356+
}
1357+
13531358
// this happens often despite the fact that it is useless
13541359
public function testExceptionTypeFalse() {
13551360
$e = new FacebookApiException(false);

0 commit comments

Comments
 (0)