-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle undefined multipart form value #212
Conversation
Hi @fijimunkii, I'm unable to reproduce the error you were seeing with undefined values. Here's the code snippet I ran to test it. A letter was successfully created: const Lob = require('lob')(process.env.API_KEY, { apiVersion: '2018-06-05' });
const config = {
double_sided: true
};
Lob.letters.create({
description: 'Lob-Node Undefined test',
to: ADDRESS ID,
from: ADDRESS ID,
file: '<html style="padding-top: 3in; margin: .5in;">HTML Letter for {{name}}</html>',
merge_variables: {
name: 'Lob'
},
color: false,
double_sided: config.double_sided,
extra_service: config.extra_service // undefined
})
.then((res) => console.log(res))
.catch((ex) => console.log(ex.message)); Which version of this library are you using? Thanks! |
Hi @pallavi - Thanks your example works for me too! So, it appears to be an issue with request and form-data. I've submitted PRs for it: In order to trigger this confusing error, the file has to be a stream (this way the lob package uses formData). Happens on node 10.10 and 11.3 with the latest version of this library Here is code that throws template.html <h1>Hi {{name}}!</h1> repro.js const Lob = require('lob')(process.env.API_KEY, { apiVersion: '2018-06-05' });
const Fs = require('fs');
const Path = require('path');
const config = {
double_sided: true
};
Lob.letters.create({
description: 'Lob-Node Undefined test',
to: /* ADDRESS ID */,
from: /* ADDRESS ID */,
file: Fs.createReadStream(Path.join(__dirname,'./template.html')),
merge_variables: {
name: 'Lob'
},
color: false,
double_sided: config.double_sided,
extra_service: config.extra_service // undefined
})
.then(console.log, console.log); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fijimunkii Thanks for the example, I was able to reproduce. Instead of throwing an error on an undefined value, we'd prefer to handle it silently and have a successful API request.
Also, could you add a unit test for this?
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for contributing :) We will merge your PR after one more approval.
-
@fijimunkii could you please squash your commits into a single commit that fits our commit message conventions:
fix(resource-base): handle undefined multipart form value
-
@ the next reviewer: i confirmed that the build passes by importing the forked branch into our repo (https://travis-ci.org/lob/lob-node/builds/486536074) (the Travis build uses an encrypted environment variable, which is not accessible to pull requests from other repositories)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
4bb5336
to
101b9bc
Compare
Undefined values passed into lob.letters.create causes a confusing
exception in the form-data module that request uses for multipart headers
For instance, if the
color
key is set with no value, we get back thisconfusing error:
Error: Cannot read property 'name' of undefined
Now we get
Error: color is undefined