Skip to content

Commit

Permalink
fix: enable debug by default
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 5, 2020
1 parent d1ea877 commit 010cdfe
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function createApp (options: AppOptions = {}): App {
// @ts-ignore
const app: Partial<App> = function (req: IncomingMessage, res: ServerResponse) {
return _handle(req, res)
.catch((err: Error | any) => { sendError(res, err, options.debug) })
.catch((err: Error | any) => { sendError(res, err, undefined, options.debug) })
}

app.stack = stack
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function defaultContentType (res: ServerResponse, type: string) {
}
}

export function sendError (res: ServerResponse, error: Error | string, debug?: boolean, code?: number) {
export function sendError (res: ServerResponse, error: Error | string, code?: number, debug: boolean = true) {
res.statusCode = code ||
(res.statusCode !== 200 && res.statusCode) ||
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('app', () => {
let request: SuperTest<Test>

beforeEach(() => {
app = createApp()
app = createApp({ debug: false })
request = supertest(app)
})

Expand Down
2 changes: 1 addition & 1 deletion test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('server', () => {
let server: Server

beforeEach(async () => {
app = createApp()
app = createApp({ debug: false })
server = new Server(app)
const port = await getPort()
server.listen(port)
Expand Down
2 changes: 1 addition & 1 deletion test/integrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('integrations with other frameworks', () => {
let request: SuperTest<Test>

beforeEach(() => {
app = createApp()
app = createApp({ debug: false })
request = supertest(app)
})

Expand Down
2 changes: 1 addition & 1 deletion test/lazy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('lazy loading', () => {
let request: SuperTest<Test>

beforeEach(() => {
app = createApp()
app = createApp({ debug: false })
request = supertest(app)
})

Expand Down
8 changes: 4 additions & 4 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('', () => {
let request: SuperTest<Test>

beforeEach(() => {
app = createApp()
app = createApp({ debug: false })
request = supertest(app)
})

Expand All @@ -24,7 +24,7 @@ describe('', () => {

describe('sendError', () => {
it('logs errors', async () => {
app.use((_req, res) => sendError(res, 'Unprocessable', undefined, 422))
app.use((_req, res) => sendError(res, 'Unprocessable', 422))
const result = await request.get('/')

expect(result.status).toBe(422)
Expand All @@ -33,14 +33,14 @@ describe('', () => {

describe('sendError', () => {
it('returns errors', async () => {
app.use((_req, res) => sendError(res, 'Unprocessable', undefined, 422))
app.use((_req, res) => sendError(res, 'Unprocessable', 422))
const result = await request.get('/')

expect(result.status).toBe(422)
})

it('logs errors in debug mode', async () => {
app.use((_req, res) => sendError(res, 'Unprocessable', true, 422))
app.use((_req, res) => sendError(res, 'Unprocessable', 422, true))
const result = await request.get('/')

expect(result.status).toBe(422)
Expand Down

0 comments on commit 010cdfe

Please sign in to comment.