Skip to content

Commit 3db6648

Browse files
authored
Merge pull request #113 from wadetandy/master
Add debugger statements
2 parents 3a6dbbe + a04206f commit 3db6648

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@types/chai": "^4.0.4",
3535
"@types/chai-as-promised": "^7.1.0",
3636
"@types/chai-things": "^0.0.32",
37+
"@types/debug": "0.0.30",
3738
"@types/fetch-mock": "5.12.2",
3839
"@types/inflected": "1.1.29",
3940
"@types/lodash": "4.14.92",
@@ -71,6 +72,7 @@
7172
"winston": "^2.3.1"
7273
},
7374
"dependencies": {
75+
"debug": "3.1.0",
7476
"eventbusjs": "0.2.0",
7577
"inflected": "2.0.3",
7678
"lodash": "4.17.10",

src/logger.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/* tslint:disable:no-console */
2+
import { IDebugger } from 'debug'
3+
const debugFactory = require('debug')
4+
5+
export const debug : IDebugger = debugFactory('jsorm')
6+
27
export enum LogLevel {
38
debug = 1,
49
info = 2,
@@ -35,6 +40,7 @@ export class Logger implements ILogger {
3540
}
3641

3742
debug(stmt: any): void {
43+
debug(stmt)
3844
if (this._level <= LogLevel.debug) {
3945
console.info(stmt)
4046
}

src/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,4 +941,4 @@ export const isModelInstance = (arg: any): arg is JSORMBase => {
941941
return false
942942
}
943943
return isModelClass(arg.constructor.currentClass)
944-
}
944+
}

src/request.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,13 @@ export class Request {
109109

110110
let json
111111
try {
112-
json = await response.json()
112+
json = await response.clone().json()
113113
} catch (e) {
114-
throw new ResponseError(response, "invalid json", e)
114+
if (response.body) {
115+
this.logger.debug(`Invalid Response JSON: ${response.text()}`)
116+
}
117+
118+
throw new ResponseError(response, `invalid json: ${json}`, e)
115119
}
116120

117121
try {

0 commit comments

Comments
 (0)