此documentation之后,我尝试从AWS api网关实现一个生成的android SDK,但是,每当api网关的响应不是200或请求参数不正确/为空时,我的应用就会崩溃。
这是API客户端对象初始化:
@Provides
@ApplicationScope
public BigCRMClient bigCRMClient() {
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setCurlLogging(true);
ApiClientFactory apiClientFactory = new ApiClientFactory();
apiClientFactory.clientConfiguration(clientConfiguration);
return apiClientFactory.build(BigCRMClient.class);
}
API调用:
Completable.create(e -> {
bigCRMClient.contactsPost(BuildConfig.BIG_CRM_TOKEN, bigCRMContact);
})
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.newThread())
.subscribe();
我试图更改线程调用,但仍然崩溃。 和崩溃日志:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.erasys.siaga, PID: 10492
Theme: themes:{default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
com.amazonaws.mobileconnectors.apigateway.ApiClientException: {
"body-json" : {"error":["duplicate key value violates unique constraint \"contacts_email_brand_id_7d9a6f1a_uniq\"\nDETAIL: Key (email, brand_id)=(adityahas@gmail.com, 19) already exists.\n"]},
"params" : {
"path" : {
}
,"querystring" : {
}
,"header" : {
"Accept" : "application\/json"
, "Accept-Encoding" : "identity"
, "Authorization" : "token b73a34e395389bc46e269ba0d52c256079c00f50"
, "Content-Type" : "application\/json"
, "Host" : "w2lyh239oi.execute-api.ap-southeast-1.amazonaws.com"
, "User-Agent" : "aws-sdk-android\/2.7.6 Linux\/3.10.49-Lineage\uFFE2\uFF84\uFFA2+ Dalvik\/2.1.0\/0 en_US BigCRMClient"
, "X-Amzn-Trace-Id" : "Root=1-5bd915de-c6a38cd8a328223013769f40"
, "X-Forwarded-For" : "36.73.117.238"
, "X-Forwarded-Port" : "443"
, "X-Forwarded-Proto" : "https"
}
},
"stage-variables" : {
},
"context" : {
"account-id" : "",
"api-id" : "w2lyh239oi",
"api-key" : "",
"authorizer-principal-id" : "",
"caller" : "",
"cognito-authentication-provider" : "",
"cognito-authentication-type" : "",
"cognito-identity-id" : "",
"cognito-identity-pool-id" : "",
"http-method" : "POST",
"stage" : "Beta",
"source-ip" : "36.73.117.238",
"user" : "",
"user-agent" : "aws-sdk-android/2.7.6 Linux/3.10.49-Lineage\uFFE2\uFF84\uFFA2+ Dalvik/2.1.0/0 en_US BigCRMClient",
"user-arn" : "",
"request-id" : "2ef1630f-dcb6-11e8-a9e4-45da7d034736",
"resource-id" : "74fckx",
"resource-path" : "/contacts"
}
}
(Service: BigCRMClient; Status Code: 400; Error Code: null; Request ID: 2ef1630f-dcb6-11e8-a9e4-45da7d034736)
at com.amazonaws.mobileconnectors.apigateway.ApiClientHandler.handleResponse(ApiClientHandler.java:294)
at com.amazonaws.mobileconnectors.apigateway.ApiClientHandler.invoke(ApiClientHandler.java:111)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at $Proxy4.contactsPost(Unknown Source)
at com.erasys.siaga.activity.login.LoginPresenter.lambda$registerCRMUser$5$LoginPresenter(LoginPresenter.java:271)
at com.erasys.siaga.activity.login.LoginPresenter$$Lambda$6.subscribe(Unknown Source)
at io.reactivex.internal.operators.completable.CompletableCreate.subscribeActual(CompletableCreate.java:39)
at io.reactivex.Completable.subscribe(Completable.java:1517)
at io.reactivex.internal.operators.completable.CompletableObserveOn.subscribeActual(CompletableObserveOn.java:34)
at io.reactivex.Completable.subscribe(Completable.java:1517)
at io.reactivex.internal.operators.completable.CompletableSubscribeOn$SubscribeOnObserver.run(CompletableSubscribeOn.java:64)
at io.reactivex.Scheduler$1.run(Scheduler.java:134)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:59)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:51)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)