Skip to content

Commit

Permalink
Merge pull request #3620 from openstax/fx3
Browse files Browse the repository at this point in the history
only attempt to parse body if it's present
  • Loading branch information
nathanstitt authored May 21, 2021
2 parents 666771c + 344f017 commit 2929d44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions shared/src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ async function request<RetT>(methodUrl: MethodUrl, options?: any): Promise<RetT|
}
const origin = options?.origin || baseUrl
const resp = await fetch(`${origin}/${url}`, req)

if (resp.ok) {
if (resp.status == 204) { // no content
return {} as RetT
const body = await resp.text()
if (body) {
return JSON.parse(body) as RetT
}
const respJson = await resp.json()
return await respJson as RetT
return {} as RetT
} else {
const err = ApiError.fromError(`${method} api/${url}`, resp, options)
try {
Expand Down
3 changes: 2 additions & 1 deletion tutor/src/helpers/payments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { readonly } from 'core-decorators';
import invariant from 'invariant';
import { NotificationActions, Logging } from 'shared';
import type { Course, User } from '../models'
import { Purchase } from '../models'
import { Purchase, currentUser } from '../models'
import { SUPPORT_EMAIL } from '../config'
import { Chat } from './chat';

Expand Down Expand Up @@ -40,6 +40,7 @@ export class Payments extends BaseModel {
super();
modelize(this);
this.options = merge({
user: currentUser,
timeoutLength: 60000,
messageHandlers: {
timeout: this.onTimeout,
Expand Down

0 comments on commit 2929d44

Please sign in to comment.