Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 7 additions & 2 deletions src/protocols/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ export default class HttpProtocol extends KuzzleAbstractProtocol {
path = `/${path}`;
}
const url = `${this.protocol}://${this.host}:${this.port}${path}`;

const headers = payload.headers || {};
headers['Content-Length'] = Buffer.byteLength(payload.body || '');

Expand All @@ -306,7 +305,13 @@ export default class HttpProtocol extends KuzzleAbstractProtocol {
body: payload.body,
timeout: this._timeout
})
.then(response => JSON.parse(response.body));
.then(response => {
if (response.statusCode === 431) {
throw new Error('Request query string is too large. Try to use the method with the POST verb instead.');
}

return JSON.parse(response.body);
});
}

// Browser implementation, using XMLHttpRequest:
Expand Down
14 changes: 13 additions & 1 deletion src/protocols/abstract/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,19 @@ Discarded request: ${JSON.stringify(request)}`));
this._pendingRequests.delete(request.requestId);

if (response.error) {
const error = new KuzzleError(response.error, stack);
let error;

// Wrap API error but directly throw errors that comes from SDK
if (response.error.id) {
error = new KuzzleError(response.error, stack);
}
else {
// Keep both stacktrace
const lines = stack.split('\n');
lines[0] = '';
response.error.stack += '\n' + lines.join('\n');
error = response.error;
}

this.emit('queryError', error, request);

Expand Down