Skip to content

Commit 19b12c7

Browse files
author
Craig Walls
committed
Refine error handling around error codes. SOCIALFB-182
1 parent bf18637 commit 19b12c7

File tree

44 files changed

+845
-275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+845
-275
lines changed

spring-social-facebook-itest/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ targetCompatibility = 1.7
1616

1717
dependencies {
1818
compile "org.springframework.social:spring-social-facebook:$springSocialFacebookVersion"
19+
compile "log4j:log4j:1.2.17"
1920
testCompile "junit:junit-dep:$junitVersion"
2021
}
2122

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.social.facebook.itest;
17+
18+
import java.util.logging.Logger;
19+
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
import org.springframework.social.facebook.api.Facebook;
23+
import org.springframework.social.facebook.api.TestUser;
24+
import org.springframework.social.facebook.api.impl.FacebookTemplate;
25+
26+
public class ErrorsITests extends FacebookITest implements ITestCredentials {
27+
28+
private static final Logger logger = Logger.getLogger(ErrorsITests.class.getName());
29+
30+
private TestUser testUser1;
31+
private Facebook fb;
32+
33+
public ErrorsITests() {
34+
super("162886103757745", "fa8a9825f555a7a8949ec48fb93bda58");
35+
}
36+
37+
@Before
38+
public void setupTestUsers() {
39+
testUser1 = createTestUser(true, "publish_actions,read_stream,user_posts,user_tagged_places", "Alice Arensen");
40+
fb = new FacebookTemplate(testUser1.getAccessToken());
41+
logger.info("CREATED TEST USERS: " + testUser1.getId());
42+
}
43+
44+
@Test
45+
public void errorTests() throws Exception {
46+
47+
String postId = fb.feedOperations().updateStatus("Hello");
48+
49+
String postId2 = fb.feedOperations().updateStatus("Hello");
50+
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
3+
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
4+
5+
<!-- Appenders -->
6+
<appender name="console" class="org.apache.log4j.ConsoleAppender">
7+
<param name="Target" value="System.out" />
8+
<layout class="org.apache.log4j.PatternLayout">
9+
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
10+
</layout>
11+
</appender>
12+
13+
<!-- Application Loggers -->
14+
<logger name="org.springframework.social">
15+
<level value="debug" />
16+
</logger>
17+
18+
<!-- Root Logger -->
19+
<root>
20+
<priority value="info" />
21+
<appender-ref ref="console" />
22+
</root>
23+
24+
</log4j:configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.social.facebook.api;
17+
18+
/**
19+
* Represents an error returned from a bad Graph API request.
20+
* @author Craig Walls
21+
*/
22+
public class FacebookError {
23+
24+
private final Integer code;
25+
26+
private final String type;
27+
28+
private final String message;
29+
30+
private final Integer subcode;
31+
32+
private final String userMessage;
33+
34+
private final String userTitle;
35+
36+
public FacebookError(Integer code, String type, String message, Integer subcode, String userMessage, String userTitle) {
37+
this.code = code != null && code != 0 ? code : null;
38+
this.type = type;
39+
this.message = message;
40+
this.subcode = subcode;
41+
this.userMessage = userMessage;
42+
this.userTitle = userTitle;
43+
}
44+
45+
public Integer getCode() {
46+
return code;
47+
}
48+
49+
public String getType() {
50+
return type;
51+
}
52+
53+
public String getMessage() {
54+
return message;
55+
}
56+
57+
public Integer getSubcode() {
58+
return subcode;
59+
}
60+
61+
public String getUserMessage() {
62+
return userMessage;
63+
}
64+
65+
public String getUserTitle() {
66+
return userTitle;
67+
}
68+
69+
}

0 commit comments

Comments
 (0)