diff --git a/js-test/test.js b/js-test/test.js index 427c99b5..e59fa819 100644 --- a/js-test/test.js +++ b/js-test/test.js @@ -176,7 +176,7 @@ QUnit.test("other mime", testCase("unknown/unknown", "any", "Bad Request")); QUnit.test("RFC 7807 - title", testCase( - "application/json", + "application/problem+json", JSON.stringify({ type: "https://tools.ietf.org/html/rfc7231#section-6.6.1", title: SAMPLE_MESSAGE, @@ -186,13 +186,20 @@ )); QUnit.test("RFC 7807 - detail fallback", testCase( - "application/json", + "application/problem+json", JSON.stringify({ detail: SAMPLE_MESSAGE }), SAMPLE_MESSAGE - )) + )); + QUnit.test("RFC 7807 - error format", testCase( + "application/problem+json", + JSON.stringify({ + some_property: SAMPLE_MESSAGE + }), + '{\"some_property\":\"' + SAMPLE_MESSAGE + '\"}' + )); }); QUnit.test("Issue #146", function(assert) { diff --git a/js/dx.aspnet.data.js b/js/dx.aspnet.data.js index 206b728a..0766e342 100644 --- a/js/dx.aspnet.data.js +++ b/js/dx.aspnet.data.js @@ -379,9 +379,23 @@ if(mime.indexOf("application/json") === 0) { var jsonObj = safeParseJSON(responseText); - if(isNonEmptyString(jsonObj)) + if(typeof jsonObj === "string") return jsonObj; + if(typeof jsonObj === "object") { + for(var key in jsonObj) { + if(typeof jsonObj[key] === "string") + return jsonObj[key]; + } + } + + return responseText; + } + + if(mime.indexOf("application/problem+json") === 0) { + var jsonObj = safeParseJSON(responseText); + + var candidate; if(typeof jsonObj === "object") { candidate = jsonObj.title; if(isNonEmptyString(candidate)) @@ -390,12 +404,6 @@ candidate = jsonObj.detail; if(isNonEmptyString(candidate)) return candidate; - - for(var key in jsonObj) { - candidate = jsonObj[key]; - if(isNonEmptyString(candidate)) - return candidate; - } } return responseText;