Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Error parsing fix #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ const create = ({
sessionId = process.env.DEGIRO_SID,
account = +process.env.DEGIRO_ACCOUNT,
debug = !!process.env.DEGIRO_DEBUG,
logging_function = () => {}
} = {}) => {
const log = debug ? (...s) => console.log(...s) : () => {};
const log = (...args) => {
logging_function(...args);
if (debug) {
console.log(...args);
}
};

const session = {
id: sessionId,
Expand All @@ -37,8 +43,11 @@ const create = ({
};

const checkSuccess = res => {
if (res.status !== 0) {
throw Error(res.message);
if (res.errors) {
let message = '';
for (const error of res.errors)
message += `\n - ${error.text}`
throw Error(message);
}
return res;
};
Expand Down Expand Up @@ -375,11 +384,7 @@ const create = ({
)
.then(res => res.json())
.then(function(res) {
if (res.status == 0 && res.statusText == 'success') {
return true;
} else {
throw Error('Delete order failed');
}
checkSuccess(res)
});
};

Expand Down