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

WIP: Handle faults returned from rtorrent #841

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ I've been bad about cutting actual releases, so check this repo for recent commi
### Local Development

1. Run `npm install`.
2. Run `npm run start:development:server` and `npm run start:development:client` in separate terminal instances.
2. Run `npm run build`.
3. Run `npm run start:development:server` and `npm run start:development:client` in separate terminal instances.
* `npm run start:development:server` uses [nodemon](https://github.com/remy/nodemon) to watch for changes to the server-side JavaScript.
* `npm run start:development:client` watches for changes in the client-side source.
3. Access the UI in your browser. Defaults to `localhost:4200`.
4. Access the UI in your browser. Defaults to `localhost:4200`.

### Environment Variables

Expand Down
6 changes: 6 additions & 0 deletions server/util/ajaxUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const ajaxUtil = {
};
}

if (typeof error === 'object' && error.faultString !== undefined) {
error = {
message: error.faultString,
}
}

res.status(500).json(error);
} else {
res.json(data);
Expand Down
9 changes: 9 additions & 0 deletions server/util/rTorrentDeserializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let tmpData;
let dataIsVal;
let endOfResponse;
let rejectCallback;
let fault;

const openTag = elementName => {
if (elementName === 'array' || elementName === 'struct') {
Expand Down Expand Up @@ -74,6 +75,10 @@ const closeTag = elementName => {
case 'member':
break;

case 'fault':
fault = true;
break;

default:
rejectCallback(`Unexpected XML-RPC Tag: ${elementName}`);
}
Expand All @@ -85,6 +90,7 @@ const deserialize = (data, resolve, reject) => {
tmpData = [];
dataIsVal = false;
endOfResponse = false;
fault = false;
rejectCallback = reject;
const parser = new saxen.Parser();
parser.on('openTag', openTag);
Expand All @@ -93,6 +99,9 @@ const deserialize = (data, resolve, reject) => {
parser.on('error', onError);
parser.parse(data);
if (endOfResponse) {
if (fault) {
return reject(dataStack[0]);
}
return resolve(dataStack[0]);
}
return reject('truncated response was received');
Expand Down