Skip to content

Commit

Permalink
minor internal refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
0x8890 committed Aug 31, 2015
1 parent 5fa58eb commit 343ed51
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/dispatch/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as success from '../common/success'
import * as methods from '../common/methods'
import { OK, Created, Empty } from '../common/success'
import { BadRequestError, NotFoundError, MethodError,
nativeErrors } from '../common/errors'

Expand Down Expand Up @@ -57,16 +57,12 @@ export default function dispatch (options, ...args) {
.then(context => processResponse(context, ...args))

.then(context => {
const { request, response } = context
let Wrapper = success.OK
const { request: { method }, response: { payload }, response } = context

if (request.method === methods.create)
Wrapper = success.Created
if (method === methods.create) return new Created(response)
if (!payload) return new Empty(response)

if (!response.payload)
Wrapper = success.Empty

return new Wrapper(response)
return new OK(response)
})

.catch(error => {
Expand Down

0 comments on commit 343ed51

Please sign in to comment.