michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.sync; michael@0: michael@0: import org.mozilla.gecko.sync.net.SyncStorageResponse; michael@0: michael@0: import android.content.SyncResult; michael@0: michael@0: public class HTTPFailureException extends SyncException { michael@0: private static final long serialVersionUID = -5415864029780770619L; michael@0: public SyncStorageResponse response; michael@0: michael@0: public HTTPFailureException(SyncStorageResponse response) { michael@0: this.response = response; michael@0: } michael@0: michael@0: @Override michael@0: public String toString() { michael@0: String errorMessage; michael@0: try { michael@0: errorMessage = this.response.getErrorMessage(); michael@0: } catch (Exception e) { michael@0: // Oh well. michael@0: errorMessage = "[unknown error message]"; michael@0: } michael@0: return ""; michael@0: } michael@0: michael@0: @Override michael@0: public void updateStats(GlobalSession globalSession, SyncResult syncResult) { michael@0: switch (response.getStatusCode()) { michael@0: case 401: michael@0: // Node reassignment 401s get handled internally. michael@0: syncResult.stats.numAuthExceptions++; michael@0: return; michael@0: case 500: michael@0: case 501: michael@0: case 503: michael@0: // TODO: backoff. michael@0: syncResult.stats.numIoExceptions++; michael@0: return; michael@0: } michael@0: } michael@0: }