feat: added http status code enum
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { AxiosInstance } from 'axios';
|
||||
import axios from 'axios';
|
||||
import { ArgumentValidator } from './models/ArgumentValidator';
|
||||
import { EndpointFactory } from './models/EndpointFactory';
|
||||
|
||||
/**
|
||||
* @class OnspringClient - A client that can communicate with the Onspring API.
|
||||
@@ -39,4 +40,19 @@ export class OnspringClient {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public async canConnect(): Promise<boolean> {
|
||||
const endpoint = EndpointFactory.getPingEndpoint(this._client.defaults.baseURL);
|
||||
try {
|
||||
var response = await this._client.get(endpoint);
|
||||
return response.status === 200;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async get<T>(endpoint: string): Promise<T> {
|
||||
const response = await this._client.get<T>(endpoint);
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
export enum HttpStatusCode {
|
||||
OK = 200,
|
||||
Created = 201,
|
||||
Accepted = 202,
|
||||
NoContent = 204,
|
||||
BadRequest = 400,
|
||||
Unauthorized = 401,
|
||||
Forbidden = 403,
|
||||
NotFound = 404,
|
||||
MethodNotAllowed = 405,
|
||||
Conflict = 409,
|
||||
InternalServerError = 500,
|
||||
NotImplemented = 501,
|
||||
BadGateway = 502,
|
||||
ServiceUnavailable = 503,
|
||||
GatewayTimeout = 504,
|
||||
}
|
||||
Reference in New Issue
Block a user