Improve request error debug output

This commit is contained in:
Toby Zerner
2015-10-21 10:47:07 +10:30
parent 14af6c0e8b
commit 2a5c0c1c7a
3 changed files with 14 additions and 4 deletions

View File

@ -206,7 +206,7 @@ export default class App {
try { try {
return JSON.parse(responseText); return JSON.parse(responseText);
} catch (e) { } catch (e) {
throw new RequestError(500, responseText); throw new RequestError(500, responseText, options, xhr);
} }
}); });
@ -230,7 +230,7 @@ export default class App {
const status = xhr.status; const status = xhr.status;
if (status < 200 || status > 299) { if (status < 200 || status > 299) {
throw new RequestError(status, responseText, xhr); throw new RequestError(status, responseText, options, xhr);
} }
return responseText; return responseText;

View File

@ -5,6 +5,12 @@ export default class RequestErrorModal extends Modal {
return 'RequestErrorModal Modal--large'; return 'RequestErrorModal Modal--large';
} }
title() {
return this.props.error.xhr
? this.props.error.xhr.status+' '+this.props.error.xhr.statusText
: '';
}
content() { content() {
let responseText; let responseText;
@ -15,7 +21,10 @@ export default class RequestErrorModal extends Modal {
} }
return <div className="Modal-body"> return <div className="Modal-body">
<pre>{responseText}</pre> <pre>
{this.props.error.options.method} {this.props.error.options.url}<br/><br/>
{responseText}
</pre>
</div>; </div>;
} }
} }

View File

@ -1,7 +1,8 @@
export default class RequestError { export default class RequestError {
constructor(status, responseText, xhr) { constructor(status, responseText, options, xhr) {
this.status = status; this.status = status;
this.responseText = responseText; this.responseText = responseText;
this.options = options;
this.xhr = xhr; this.xhr = xhr;
try { try {