Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/form/FormController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class FormController<T extends GenericState> {
* Keep track of raw input data as provided by the
* user
*/
private inputs: {[K in keyof T]?: string};
private inputs: { [K in keyof T]?: string };

/**
* The parsers defined for this form
Expand Down Expand Up @@ -113,14 +113,13 @@ export class FormController<T extends GenericState> {
},
body: JSON.stringify(this.state),
});
if (res.status === 500) {
if (res.status >= 500 && res.status <= 600) {
const response = await res.json();
throw new Error(response.message);
} else if (res.status === 200) {
const response = await res.json();
this.responseHandler(response);
} else {
// const response = await res.text();
throw new Error(res.statusText);
}
} catch (err) {
Expand Down Expand Up @@ -154,7 +153,7 @@ export class FormController<T extends GenericState> {
set<K extends keyof T>(name: K, newValue: T[K]) {
// Object only if value changes
if (newValue === this.state[name]) return;
this.state = Object.assign({}, this.state, {[name]: newValue});
this.state = Object.assign({}, this.state, { [name]: newValue });
const listeners = this.listeners[name];
if (listeners) listeners.forEach(l => l(newValue));
}
Expand Down