Added NotFoundException for 404 Not Found

parent 429648cf
......@@ -36,6 +36,7 @@ import java.util.Set;
import at.bitfire.dav4android.exception.DavException;
import at.bitfire.dav4android.exception.HttpException;
import at.bitfire.dav4android.exception.InvalidDavResponseException;
import at.bitfire.dav4android.exception.NotFoundException;
import at.bitfire.dav4android.exception.UnauthorizedException;
import at.bitfire.dav4android.exception.PreconditionFailedException;
import at.bitfire.dav4android.exception.ServiceUnavailableException;
......@@ -192,6 +193,8 @@ public class DavResource {
switch (code) {
case 401:
throw response != null ? new UnauthorizedException(response) : new UnauthorizedException(message);
case 404:
throw response != null ? new NotFoundException(response) : new NotFoundException(message);
case 412:
throw response != null ? new PreconditionFailedException(response) : new PreconditionFailedException(message);
case 503:
......
package at.bitfire.dav4android;
import android.text.TextUtils;
import com.squareup.okhttp.HttpUrl;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
public class UrlUtils {
......@@ -23,6 +26,20 @@ public class UrlUtils {
}
}
/**
* Returns the last non-empty path segment of the given URL, or "" if none.
*/
public static String lastSegment(HttpUrl url) {
String segment = "";
List<String> segments = url.pathSegments();
for (int i = segments.size()-1; i >= 0; i--) {
segment = segments.get(i);
if (!TextUtils.isEmpty(segment))
break;
}
return segment;
}
public static HttpUrl omitTrailingSlash(HttpUrl url) {
int idxLast = url.pathSize() - 1;
boolean hasTrailingSlash = "".equals(url.pathSegments().get(idxLast));
......
/*
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.dav4android.exception;
import com.squareup.okhttp.Response;
public class NotFoundException extends HttpException {
public NotFoundException(Response response) {
super(response);
}
public NotFoundException(String message) {
super(404, message);
}
}
......@@ -59,7 +59,7 @@ public class CalendarColor implements Property {
int color_alpha = m.group(2) != null ? (Integer.parseInt(m.group(2), 16) & 0xFF) : 0xFF;
color = (color_alpha << 24) | color_rgb;
} else
Constants.log.warn("Couldn't parse color " + davColor + ", using DAVdroid green");
Constants.log.warn("Couldn't parse color " + davColor + ", ignoring");
}
return color;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment