Skip to content

Commit 151544a

Browse files
Fix support RFC 7807 format (T1156273) (#590)
1 parent 1dcc20e commit 151544a

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

js-test/test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
QUnit.test("other mime", testCase("unknown/unknown", "any", "Bad Request"));
177177

178178
QUnit.test("RFC 7807 - title", testCase(
179-
"application/json",
179+
"application/problem+json",
180180
JSON.stringify({
181181
type: "https://tools.ietf.org/html/rfc7231#section-6.6.1",
182182
title: SAMPLE_MESSAGE,
@@ -186,13 +186,20 @@
186186
));
187187

188188
QUnit.test("RFC 7807 - detail fallback", testCase(
189-
"application/json",
189+
"application/problem+json",
190190
JSON.stringify({
191191
detail: SAMPLE_MESSAGE
192192
}),
193193
SAMPLE_MESSAGE
194-
))
194+
));
195195

196+
QUnit.test("RFC 7807 - error format", testCase(
197+
"application/problem+json",
198+
JSON.stringify({
199+
some_property: SAMPLE_MESSAGE
200+
}),
201+
'{\"some_property\":\"' + SAMPLE_MESSAGE + '\"}'
202+
));
196203
});
197204

198205
QUnit.test("Issue #146", function(assert) {

js/dx.aspnet.data.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,23 @@
379379
if(mime.indexOf("application/json") === 0) {
380380
var jsonObj = safeParseJSON(responseText);
381381

382-
if(isNonEmptyString(jsonObj))
382+
if(typeof jsonObj === "string")
383383
return jsonObj;
384384

385+
if(typeof jsonObj === "object") {
386+
for(var key in jsonObj) {
387+
if(typeof jsonObj[key] === "string")
388+
return jsonObj[key];
389+
}
390+
}
391+
392+
return responseText;
393+
}
394+
395+
if(mime.indexOf("application/problem+json") === 0) {
396+
var jsonObj = safeParseJSON(responseText);
397+
398+
var candidate;
385399
if(typeof jsonObj === "object") {
386400
candidate = jsonObj.title;
387401
if(isNonEmptyString(candidate))
@@ -390,12 +404,6 @@
390404
candidate = jsonObj.detail;
391405
if(isNonEmptyString(candidate))
392406
return candidate;
393-
394-
for(var key in jsonObj) {
395-
candidate = jsonObj[key];
396-
if(isNonEmptyString(candidate))
397-
return candidate;
398-
}
399407
}
400408

401409
return responseText;

0 commit comments

Comments
 (0)