all files / lib/html-parsers/ false-error-codes.js

0% Statements 0/2
0% Branches 0/4
0% Functions 0/4
0% Lines 0/2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                                         
'use strict'
 
import trumpet from 'trumpet'
import { trumpetInnerText } from './index'
import JsonStream from 'JSONStream'
 
// Myfox page not found is a code 200... must fix it!
const notFound200 = function () {
  const parser = trumpet()
  parser.select('head title', trumpetInnerText((data) => {
    parser.status = 200
    if (data.indexOf('Page not found') !== -1) {
      parser.status = 404
      const error = new Error('Page not found case returned by Myfox.')
      error.status = 404
      return parser.emit('error', error)
    }
  }))
  return parser
}
 
// Myfox code KO is a code 200... must fix it and return error messages.
const codeKo200 = function () {
  const parser = JsonStream.parse('code')
  parser.on('data', (data) => {
    if (data === 'KO') {
      const error = new Error('Code KO returned by Myfox.')
      error.status = 400
      return parser.emit('error', error)
    }
  })
  return parser
}
 
export { notFound200 as notFound200 }
export { codeKo200 as codeKo200 }