Removed errors results as JSON, moved to exception throwing; Changed error messages

This commit is contained in:
alexandercerutti
2018-08-11 00:13:06 +02:00
parent cc23930a2f
commit af6ab80702

View File

@@ -31,23 +31,19 @@ class Pass {
return this._parseSettings(this.options)
.then(() => readdir(this.model))
.catch(() => Promise.reject({
status: false,
error: {
message: `Model ${this.model} not found. Provide a valid one to continue`
.catch((err) => {
if (err.code && err.code === "ENOENT") {
throw new Error(`Model ${this.model ? this.model+" " : ""}not found. Provide a valid one to continue`);
}
}))
throw new Error(err);
})
.then(files => {
// list without dynamic components like manifest, signature or pass files (will be added later in the flow) and hidden files.
let noDynList = removeHidden(files).filter(f => !/(manifest|signature|pass)/i.test(f));
if (!noDynList.length) {
return Promise.reject({
status: false,
error: {
message: "Model provided matched but unitialized. Refer to https://apple.co/2IhJr0Q and documentation to fill the model correctly."
}
});
throw new Error(`Provided model (${path.parse(this.model).name}) matched but unitialized. Refer to https://apple.co/2IhJr0Q and documentation to fill the model correctly.`);
}
// list without localization files (they will be added later in the flow)
@@ -65,26 +61,12 @@ class Pass {
return readFile(path.resolve(this.model, "pass.json"))
.then(passStructBuffer => {
if (!this._validateType(passStructBuffer)) {
return Promise.reject({
status: false,
error: {
message: `Unable to validate pass type or pass file is not a valid buffer. Check the syntax of your pass.json file or refer to https://apple.co/2Nvshvn to use a valid type.`
}
});
throw new Error(`Unable to validate pass type or pass file is not a valid buffer. Check the syntax of your pass.json file or refer to https://apple.co/2Nvshvn to use a valid type.`)
}
bundle.push("pass.json");
return this._patch(this._filterOptions(this.overrides), passStructBuffer);
})
.catch(err => {
console.log(err);
return Promise.reject({
status: false,
error: {
message: `Unable to validate pass type or pass file is not a valid buffer. Check the syntax of your pass.json file or refer to https://apple.co/2Nvshvn to use a valid type.`
}
})
});
});
@@ -126,12 +108,7 @@ class Pass {
archive.pipe(passStream);
return archive.finalize().then(() => {
return {
status: true,
content: passStream,
};
});
return archive.finalize().then(() => passStream);
});
}
@@ -232,9 +209,8 @@ class Pass {
*/
_patch(options, passBuffer) {
return new Promise((resolve, reject) => {
if (!options) {
return resolve(passBuffer);
return Promise.resolve(passBuffer);
}
let passFile = JSON.parse(passBuffer.toString("utf8"));
@@ -279,8 +255,7 @@ class Pass {
Object.assign(passFile, options);
return resolve(Buffer.from(JSON.stringify(passFile)));
});
return Promise.resolve(Buffer.from(JSON.stringify(passFile)));
}
/**
@@ -313,23 +288,12 @@ class Pass {
_parseSettings(options) {
if (!schema.isValid(options, schema.constants.instance)) {
return Promise.reject({
status: false,
error: {
message: "The options passed to Pass constructor does not meet the requirements. Refer to the documentation to compile them correctly."
}
});
return Promise.reject("The options passed to Pass constructor does not meet the requirements. Refer to the documentation to compile them correctly.");
}
return new Promise((success, reject) => {
if (!options.model || typeof options.model !== "string") {
return reject({
status: false,
error: {
message: "A string model name must be provided in order to continue.",
ecode: 418
}
});
return reject("A string model name must be provided in order to continue.");
}
this.model = path.resolve(options.model) + (!!options.model && !path.extname(options.model) ? ".pass" : "");
@@ -346,13 +310,7 @@ class Pass {
contents.forEach(file => {
let pem = this.__parsePEM(file, options.certificates.signerKey.passphrase);
if (!pem) {
return reject({
status: false,
error: {
message: "Invalid certificates got loaded. Please provide WWDR certificates and developer signer certificate and key (with passphrase).",
ecode: 418
}
})
return reject("Invalid certificates got loaded. Please provide WWDR certificates and developer signer certificate and key (with passphrase).")
}
this.Certificates[pem.key] = pem.value;