Skip to content

Could it be a problem to use a fetch? #2979

Answered by ronag
krutoo asked this question in Q&A
Discussion options

You must be logged in to vote

It will be a problem. You can dump the body before throwing.

async function middleware (request, next) {
  const response = await next(request);

  if (isInvalidHeaders(response)) {
    dump(response)
    throw Error('Validation error...')
  }

  return response;
}
async function dump(response) {
  try {
    for await (const chunk of response) {
      return
    }
  } catch { 
    // Do nothing
  }
} 

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@krutoo
Comment options

@ronag
Comment options

@krutoo
Comment options

@jdalton
Comment options

@krutoo
Comment options

Answer selected by krutoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants