canned
canned copied to clipboard
Improve Error Message for invalid syntax
I observe the following:
pmu:tmp pmu$ mkdir api
pmu:tmp pmu$ cat > api/posts.json
[ "123" ]
pmu:tmp pmu$ canned
starting canned on port 3000 for ./
request: get /api/posts.json
/usr/local/share/npm/lib/node_modules/canned/lib/response.js:17
this.cors_enabled = !!options.cors_enabled
^
TypeError: Cannot read property 'cors_enabled' of undefined
at new Response (/usr/local/share/npm/lib/node_modules/canned/lib/response.js:17:32)
at /usr/local/share/npm/lib/node_modules/canned/canned.js:194:48
at Object.oncomplete (fs.js:107:15)
Maybe I am missing something?
Ok I think this error is happening on an older version of canned what version are you using right now? Can you try to reproduce with the current master?
The actual error is that api/posts.json is not valid file format for canned since it is missing the HTTP Verb and posts is not a valid keyword, what would be valid is _posts.get.json which is probably what you want. But personally I would create a structure like so:
pi(master*)$ tree [INS]
.
└── posts
└── index.get.json
1 directory, 1 file
Which would result in requests like curl localhost:3000/api/posts/ since this will serve the directory index file by default.
Still I think the error is not helpful at all so I would love to create better messages for issues like this, but for this I need to reproduce the error, any help is greatly appreciated!
Any update about this error?