'use strict';

const rq = require('request-promise');
const asyncMiddleware = require('../../deps/asyncMiddleware');
const Koas = require('../..');

let requestAction = (contentType,port) => {
	return rq({
		uri:'http://localhost:'+port,
		resolveWithFullResponse: true,
		headers: {
   			'Content-Type': contentType
    	}
	});
}
describe('koas server error test 500',() => {
	let app = new Koas();
	app.use(async (ctx, next) => {
		var err = new Error('error test');
		err.code = '500 inter error';
		throw err;
		await next();
	});
	let server = app.listen('8012');
	it('if 8012 port request 500 error',async () => {
		expect.assertions(2);
		try{
			await requestAction('text/html','8012')
		}catch(e){
			expect(e.statusCode).toEqual(500);
		}
		try{
			await requestAction('application/json','8012')
		}catch(e){
			expect(e.statusCode).toEqual(500);
		}
		server.close(error => {
			test('Could not stop server',() => {
				expect(error).toBe('')
			});
		});
	});
});
describe('koas server error test 404',() => {
	let app = new Koas();
	app.use(async (ctx, next) => {
		ctx.status = 404;
		await next();
	});
	let server = app.listen('8013');
	it('if 8013 port request 404 error',async () => {
		expect.assertions(2);
		try{
			await requestAction('text/html','8013')
		}catch(e){
			//console.log(e)
			expect(e.statusCode).toEqual(404);
		}
		try{
			await requestAction('application/json','8013')
		}catch(e){
			expect(e.statusCode).toEqual(404);
		}
		server.close(error => {
			test('Could not stop server',() => {
				expect(error).toBe('')
			});
		});
	});
});
@@ -484,21 +484,40 @@
 '500
- inter error'
+';%0A%09%09ctx.type = ctx.request.type
 ;%0A%09%09
@@ -645,35 +645,141 @@
 pect.assertions(
-2);
+3);%0A%09%09try%7B%0A%09%09%09await requestAction('text/plain','8012')%0A%09%09%7Dcatch(e)%7B%0A%09%09%09expect(e.statusCode).toEqual(500);%0A%09%09%7D
 %0A%09%09try%7B%0A%09%09%09await
@@ -1373,33 +1373,40 @@
 uestAction('
-text/html
+application/json
 ','8013')%0A%09%09
@@ -1420,28 +1420,8 @@
 e)%7B%0A
-%09%09%09//console.log(e)%0A
 %09%09%09e
@@ -1485,39 +1485,33 @@
 uestAction('
-application/jso
+text/plai
 n','8013')%0A%09
@@ -1514,32 +1514,52 @@
 ')%0A%09%09%7Dcatch(e)%7B%0A
+%09%09%09//console.log(e)%0A
 %09%09%09expect(e.stat

add test case