Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
## [1.2.0] - 2019-06-02
- Added reportError endpoint

## [1.1.0] - 2019-05-19
- First release
- First release
6 changes: 3 additions & 3 deletions development.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import { ServiceAI } from '@deepcode/tsc';
const AI = new ServiceAI();

async login() {
const { sessionToken } = await AI.startSession({
const { sessionToken } = await AI.startSession({
baseURL: 'https://www.deepcode.ai',
source: 'atom'
source: 'atom'
});
return Promise.resolve(sessionToken);
}
```
```
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deepcode/tsc",
"version": "1.1.0",
"version": "1.2.0",
"description": "Typescript consumer of Deepcode public API",
"main": "build/index.js",
"module": "build/index.es.js",
Expand Down
3 changes: 3 additions & 0 deletions src/constants/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ export const ERRORS = {
403: 'Unauthorized access to requested bundle',
other: 'Getting analysis failed',
},
[RequestTypes.reportError]: {
other: 'Reporting error failed',
},
};
12 changes: 12 additions & 0 deletions src/dto/report-error.request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { BaseDto } from './base.dto';

export class ReportErrorRequestDto extends BaseDto<ReportErrorRequestDto> {
readonly baseURL: string;
readonly sessionToken?: string;
readonly source?: string;
readonly type?: string;
readonly message?: string;
readonly path?: string;
readonly bundleId?: string;
readonly data?: any;
}
4 changes: 4 additions & 0 deletions src/dto/report-error.response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { BaseDto } from './base.dto';

export class ReportErrorResponseDto extends BaseDto<ReportErrorResponseDto> {
}
1 change: 1 addition & 0 deletions src/enums/request-types.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export enum RequestTypes {
extendBundle = 'extendBundle',
uploadFiles = 'uploadFiles',
getAnalysis = 'getAnalysis',
reportError = 'reportError',
}
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ExtendBundleResponse,
UploadFilesResponse,
GetAnalysisResponse,
ReportErrorResponse,
} from './interfaces/service-ai.interface';

import { StartSessionRequestDto } from './dto/start-session.request.dto';
Expand All @@ -27,6 +28,8 @@ import { UploadFilesRequestDto } from './dto/upload-files.request.dto';
import { UploadFilesResponseDto } from './dto/upload-files.response.dto';
import { GetAnalysisRequestDto } from './dto/get-analysis.request.dto';
import { GetAnalysisResponseDto } from './dto/get-analysis.response.dto';
import { ReportErrorRequestDto } from './dto/report-error.request.dto';
import { ReportErrorResponseDto } from './dto/report-error.response.dto';
import { AnalyseRequestDto } from './dto/analyse.request.dto';
import { IQueueAnalysisCheckResult } from './interfaces/queue.interface';

Expand All @@ -44,6 +47,7 @@ export {
ExtendBundleResponse,
UploadFilesResponse,
GetAnalysisResponse,
ReportErrorResponse,

StartSessionRequestDto,
StartSessionResponseDto,
Expand All @@ -60,6 +64,8 @@ export {
UploadFilesResponseDto,
GetAnalysisRequestDto,
GetAnalysisResponseDto,
ReportErrorRequestDto,
ReportErrorResponseDto,
AnalyseRequestDto,
IQueueAnalysisCheckResult,
};
9 changes: 9 additions & 0 deletions src/interfaces/service-ai.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { UploadFilesRequestDto } from '../dto/upload-files.request.dto';
import { UploadFilesResponseDto } from '../dto/upload-files.response.dto';
import { GetAnalysisRequestDto } from '../dto/get-analysis.request.dto';
import { GetAnalysisResponseDto } from '../dto/get-analysis.response.dto';
import { ReportErrorRequestDto } from '../dto/report-error.request.dto';
import { ReportErrorResponseDto } from '../dto/report-error.response.dto';

export type StartSessionResponse = StartSessionResponseDto | ErrorResponseDto;
export type GetFiltersResponse = GetFiltersResponseDto | ErrorResponseDto;
Expand All @@ -23,6 +25,7 @@ export type CheckBundleResponse = CheckBundleResponseDto | ErrorResponseDto;
export type ExtendBundleResponse = ExtendBundleResponseDto | ErrorResponseDto;
export type UploadFilesResponse = UploadFilesResponseDto | ErrorResponseDto;
export type GetAnalysisResponse = GetAnalysisResponseDto | ErrorResponseDto;
export type ReportErrorResponse = ReportErrorResponseDto | ErrorResponseDto;

export interface IServiceAI {
/**
Expand Down Expand Up @@ -72,4 +75,10 @@ export interface IServiceAI {
* @param options
*/
getAnalysis(options: GetAnalysisRequestDto): Promise<GetAnalysisResponse>;

/**
* Reports an error
* @param options
*/
reportError(options: ReportErrorRequestDto): Promise<ReportErrorResponse>;
}
28 changes: 28 additions & 0 deletions src/modules/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ExtendBundleResponse,
UploadFilesResponse,
GetAnalysisResponse,
ReportErrorResponse,
} from '../interfaces/service-ai.interface';

import { ErrorResponseDto } from '../dto/error.response.dto';
Expand All @@ -33,6 +34,8 @@ import { UploadFilesRequestDto } from '../dto/upload-files.request.dto';
import { UploadFilesResponseDto } from '../dto/upload-files.response.dto';
import { GetAnalysisRequestDto } from '../dto/get-analysis.request.dto';
import { GetAnalysisResponseDto } from '../dto/get-analysis.response.dto';
import { ReportErrorRequestDto } from '../dto/report-error.request.dto';
import { ReportErrorResponseDto } from '../dto/report-error.response.dto';

export class Http {
private agent = new Agent(true);
Expand All @@ -48,6 +51,7 @@ export class Http {
this.createBundle = this.createBundle.bind(this);
this.getFilters = this.getFilters.bind(this);
this.startSession = this.startSession.bind(this);
this.reportError = this.reportError.bind(this);
this.createHeaders = this.createHeaders.bind(this);
}

Expand Down Expand Up @@ -254,4 +258,28 @@ export class Http {
return Promise.reject(this.createErrorResponse(error, RequestTypes.getAnalysis));
}
}

public async reportError(options: ReportErrorRequestDto): Promise<ReportErrorResponse> {
const { baseURL, sessionToken, source, type, message, path, bundleId, data } = options;
const config: AxiosRequestConfig = {
url: `${baseURL}${apiPath}/error`,
method: 'POST',
data: {
sessionToken,
source,
type,
message,
path,
bundleId,
data
},
};

try {
await this.agent.request(config);
return Promise.resolve(new ReportErrorResponseDto({}));
} catch (error) {
return Promise.reject(this.createErrorResponse(error, RequestTypes.reportError));
}
}
}
6 changes: 6 additions & 0 deletions src/modules/ServiceAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ExtendBundleResponse,
UploadFilesResponse,
GetAnalysisResponse,
ReportErrorResponse,
} from '../interfaces/service-ai.interface';

import { StartSessionRequestDto } from '../dto/start-session.request.dto';
Expand All @@ -30,6 +31,7 @@ import { GetAnalysisRequestDto } from '../dto/get-analysis.request.dto';
import { AnalyseRequestDto } from '../dto/analyse.request.dto';
import { CheckBundleResponseDto } from '../dto/check-bundle.response.dto';
import { ExtendBundleResponseDto } from '../dto/extend-bundle.response.dto';
import { ReportErrorRequestDto } from '../dto/report-error.request.dto';

export class ServiceAI implements IServiceAI {
private files = new Files();
Expand Down Expand Up @@ -78,6 +80,10 @@ export class ServiceAI implements IServiceAI {
return this.http.getAnalysis(options);
}

public async reportError(options: ReportErrorRequestDto): Promise<ReportErrorResponse> {
return this.http.reportError(options);
}

public async processUploadFiles(
baseURL: string,
sessionToken: string,
Expand Down
12 changes: 11 additions & 1 deletion tests/ServiceAI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
extendBundleRequest,
extendBundleRequestExpired,
uploadFilesRequest,
reportErrorRequest,
} from './mocks/requests';
import {
startSessionResponse,
Expand All @@ -26,6 +27,7 @@ import {
getAnalysisResponse,
checkBundleError404,
extendBundleError404,
reportErrorResponse,
} from './mocks/responses';
// import { AnalyseRequestDto } from '../src/dto/analyse.request.dto';

Expand All @@ -43,7 +45,15 @@ async function sleep(timeout: number): Promise<void> {

describe('Requests to public API', () => {
const AI = new ServiceAI();


/**
* Report error
*/
it('reports error successfully', async () => {
const response = await AI.reportError(reportErrorRequest);
expect(response).toEqual(reportErrorResponse);
});

/**
* Start Session
*/
Expand Down
9 changes: 8 additions & 1 deletion tests/mocks/mock-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
extendBundleResponse,
uploadFilesResponse,
getAnalysisResponse,
reportErrorResponse,

checkBundleError404,
} from './responses';
Expand All @@ -31,6 +32,7 @@ export function startMockServer(): void {
uploadFilesSuccess(mockServer);
getAnalysisSuccess(mockServer);
getAnalysisResult(mockServer);
reportError(mockServer);

checkBundleError(mockServer);
extendBundleError(mockServer);
Expand Down Expand Up @@ -60,6 +62,12 @@ function startSessionSuccess(mockServer: Scope): void {
.reply(200, startSessionResponse);
}

function reportError(mockServer: Scope): void {
mockServer
.post('/error')
.reply(200, reportErrorResponse);
}

function checkSessionSuccess(mockServer: Scope): void {
// URL looks like '/session?cache=270956.22901860584'
mockServer
Expand Down Expand Up @@ -129,4 +137,3 @@ function extendBundleError(mockServer: Scope): void {
.put(`/bundle/${expiredBundleId}`)
.reply(404, extendBundleResponse);
}

19 changes: 19 additions & 0 deletions tests/mocks/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IFiles } from '../../src/interfaces/files.interface';
import { CreateBundleRequestDto } from '../../src/dto/create-bundle.request.dto';
import { ExtendBundleRequestDto } from '../../src/dto/extend-bundle.request.dto';
import { UploadFilesRequestDto } from '../../src/dto/upload-files.request.dto';
import { ReportErrorRequestDto } from '../../src/dto/report-error.request.dto';

import { defaultBaseURL as baseURL } from '../../src/constants/common';
import { sessionToken, bundleId, expiredBundleId } from './base-config';
Expand Down Expand Up @@ -99,3 +100,21 @@ export const uploadFilesRequest = new UploadFilesRequestDto({
},
],
});

export const reportErrorRequest = new ReportErrorRequestDto({
baseURL,
sessionToken,
bundleId,
source: 'testSource',
type: 'testType',
message: 'testMessage',
path: '/test/path',
data: {
foo: 'bar',
bar: [
'fo',
'foo',
'fooo'
]
}
});
3 changes: 3 additions & 0 deletions tests/mocks/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CheckBundleResponseDto } from '../../src/dto/check-bundle.response.dto'
import { ExtendBundleResponseDto } from '../../src/dto/extend-bundle.response.dto';
import { UploadFilesResponseDto } from '../../src/dto/upload-files.response.dto';
import { GetAnalysisResponseDto } from '../../src/dto/get-analysis.response.dto';
import { ReportErrorResponseDto } from '../../src/dto/report-error.response.dto';

import { ERRORS } from '../../src/constants/errors';
import { AnalysisStatus } from '../../src/enums/analysis-status.enum';
Expand Down Expand Up @@ -93,3 +94,5 @@ export const extendBundleError404 = new ErrorResponseDto({
statusCode: 404,
statusText: ERRORS[RequestTypes.extendBundle][404],
});

export const reportErrorResponse = new ReportErrorResponseDto({});