REST API exception cleanup
diff --git a/planetstack/core/xoslib/methods/sliceplus.py b/planetstack/core/xoslib/methods/sliceplus.py
index 0539e62..cdb2f73 100644
--- a/planetstack/core/xoslib/methods/sliceplus.py
+++ b/planetstack/core/xoslib/methods/sliceplus.py
@@ -7,8 +7,7 @@
from django.forms import widgets
from core.xoslib.objects.sliceplus import SlicePlus
from plus import PlusSerializerMixin
-from xosapibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView
-from rest_framework.exceptions import PermissionDenied as RestFrameworkPermissionDenied
+from xosapibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
if hasattr(serializers, "ReadOnlyField"):
# rest_framework 3.x
@@ -82,7 +81,7 @@
current_user_can_see = self.request.QUERY_PARAMS.get('current_user_can_see', False)
if (not self.request.user.is_authenticated()):
- raise RestFrameworkPermissionDenied("You must be authenticated in order to use this API")
+ raise XOSPermissionDenied("You must be authenticated in order to use this API")
slices = SlicePlus.select_by_user(self.request.user)
@@ -108,7 +107,7 @@
def get_queryset(self):
if (not self.request.user.is_authenticated()):
- raise RestFrameworkPermissionDenied("You must be authenticated in order to use this API")
+ raise XOSPermissionDenied("You must be authenticated in order to use this API")
return SlicePlus.select_by_user(self.request.user)
diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
index a055093..2779cd0 100644
--- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
+++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
@@ -145,18 +145,21 @@
parsed_error=undefined;
width=640; // django stacktraces like wide width
}
+
console.log(responseText);
console.log(parsed_error);
+ if (parsed_error && ("detail" in parsed_error)) {
+ parsed_error = parsed_error["detail"];
+ }
+
if (parsed_error && ("error" in parsed_error)) {
+ if ((!parsed_error.reasons) && (parsed_error.fields)) {
+ // deal with me renaming 'reasons' to 'fields'
+ parsed_error.reasons = parsed_error.fields;
+ }
// this error comes from genapi views
$("#xos-error-dialog").html(templateFromId("#xos-error-response")(parsed_error));
- } else if (parsed_error && ("detail" in parsed_error)) {
- // this error response comes from rest_framework APIException
- parsed_error["error"] = "API Error";
- parsed_error["specific_error"] = parsed_error["detail"];
- parsed_error["reasons"] = [];
- $("#xos-error-dialog").html(templateFromId("#xos-error-response")(parsed_error));
} else {
$("#xos-error-dialog").html(templateFromId("#xos-error-rawresponse")({responseText: strip_scripts(responseText)}))
}