How to use the @terascope/job-components.TSError function in @terascope/job-components

To help you get started, we’ve selected a few @terascope/job-components examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terascope / teraslice / packages / teraslice-client-js / src / executions.ts View on Github external
async submit(jobSpec: JobConfig, shouldNotStart?: boolean): Promise {
        if (!jobSpec) throw new TSError('submit requires a jobSpec');
        const job: JobIDResponse = await this.post('/jobs', jobSpec, { query: { start: !shouldNotStart } });
        // support older version of teraslice
        if (!job.ex_id) {
            const { ex_id: exId } = await this.get(`/jobs/${job.job_id}/ex`);
            return this.wrap(exId);
        }
        return this.wrap(job.ex_id);
    }
github terascope / teraslice / packages / teraslice-client-js / src / client.ts View on Github external
function makeErrorFromResponse(response: any): OldErrorOutput {
    const { statusCode } = response;
    const stuff = getErrorFromResponse(response);
    const {
        message = STATUS_CODES[statusCode],
        code = statusCode
    } = stuff;
    const error: Partial = new TSError(message);
    error.error = code; // for legacy support
    error.code = code;
    error.statusCode = code;
    return error as OldErrorOutput;
}
github terascope / teraslice / packages / teraslice-client-js / src / job.ts View on Github external
constructor(config: ClientConfig, jobId: string) {
        super(config);
        if (!jobId) {
            throw new TSError('Job requires jobId');
        }
        if (!isString(jobId)) {
            throw new TSError('Job requires jobId to be a string');
        }
        this._jobId = jobId;
        this.slicer = _deprecateSlicerName(this.slicer);
        // @ts-ignore
        autoBind(this);
    }
github terascope / teraslice / packages / teraslice-client-js / src / client.ts View on Github external
const newEndpoint = getAPIEndpoint(endpoint, this._apiVersion);
        try {
            const response = await this._request[method](newEndpoint, options);
            const { body } = response;
            return body;
        } catch (err) {
            const { statusCode } = err;

            if (statusCode >= 400) {
                const error = makeErrorFromResponse(err);
                throw error;
            }

            // TODO: what additional parameters should we return here?
            throw new TSError(err);
        }
    }
github terascope / teraslice / packages / teraslice-client-js / src / ex.ts View on Github external
async changeWorkers(
        action: ChangeWorkerQueryParams,
        workerNum: number,
        requestOptions: RequestOptions = {}
    ): Promise {
        if (action == null || workerNum == null) {
            throw new TSError('changeWorkers requires action and count');
        }
        if (!['add', 'remove', 'total'].includes(action)) {
            throw new TSError('changeWorkers requires action to be one of add, remove, or total');
        }

        const query = { [action]: workerNum };
        requestOptions.json = false;
        const options = this.makeOptions(query, requestOptions);

        const response = await this.post(`/ex/${this._exId}/_workers`, null, options);
        // for backwards compatability
        if (typeof response === 'string') {
            try {
                return this.parse(response);
            } catch (err) {
                // do nothing
github terascope / teraslice / packages / teraslice-client-js / src / ex.ts View on Github external
function validateExId(exId?: string) {
    if (!exId) {
        throw new TSError('Ex requires exId');
    }
    if (!isString(exId)) {
        throw new TSError('Ex requires exId to be a string');
    }
}
github terascope / teraslice / packages / teraslice-client-js / src / client.ts View on Github external
private async _makeRequest(
        method: string,
        endpoint: string,
        searchOptions: SearchOptions = {},
        data?: any
    ) {
        const errorMsg = validateRequestOptions(endpoint, searchOptions);
        if (errorMsg) return Promise.reject(new TSError(errorMsg));

        let options;
        if (data) {
            options = getRequestOptionsWithData(data, searchOptions);
        } else {
            options = searchOptions;
        }

        const newEndpoint = getAPIEndpoint(endpoint, this._apiVersion);
        try {
            const response = await this._request[method](newEndpoint, options);
            const { body } = response;
            return body;
        } catch (err) {
            const { statusCode } = err;
github terascope / teraslice / packages / teraslice-client-js / src / ex.ts View on Github external
function validateExId(exId?: string) {
    if (!exId) {
        throw new TSError('Ex requires exId');
    }
    if (!isString(exId)) {
        throw new TSError('Ex requires exId to be a string');
    }
}