@internetarchive/search-service
Advanced tools
Comparing version 0.0.1-alpha.15 to 0.0.1-alpha.16
import { FieldParserInterface, FieldParserRawValue } from '../field-parser-interface'; | ||
import { MetadataField } from '../metadata-field'; | ||
/** | ||
* A Byte is a unit-specific `number`, in bytes. | ||
*/ | ||
export declare type Byte = number; | ||
@@ -4,0 +7,0 @@ /** |
@@ -14,2 +14,3 @@ import { SearchBackendInterface } from './search-backend-interface'; | ||
private fetchUrl; | ||
private getErrorResult; | ||
} |
@@ -28,5 +28,3 @@ import { Result } from '../responses/result'; | ||
const message = err instanceof Error ? err.message : err; | ||
const error = new SearchServiceError(SearchServiceErrorType.networkError, message); | ||
const result = new Result(undefined, error); | ||
return result; | ||
return this.getErrorResult(SearchServiceErrorType.networkError, message); | ||
} | ||
@@ -36,13 +34,25 @@ // then try json decoding and return a decodingError if it fails | ||
const json = await response.json(); | ||
const result = new Result(json); | ||
return result; | ||
// the advanced search endpoint doesn't return an HTTP Error 400 | ||
// and instead returns an HTTP 200 with an `error` key in the payload | ||
const error = json['error']; | ||
if (error) { | ||
const forensics = json['forensics']; | ||
return this.getErrorResult(SearchServiceErrorType.searchEngineError, error, forensics); | ||
} | ||
else { | ||
// success | ||
return new Result(json, undefined); | ||
} | ||
} | ||
catch (err) { | ||
const message = err instanceof Error ? err.message : err; | ||
const error = new SearchServiceError(SearchServiceErrorType.decodingError, message); | ||
const result = new Result(undefined, error); | ||
return result; | ||
return this.getErrorResult(SearchServiceErrorType.decodingError, message); | ||
} | ||
} | ||
getErrorResult(errorType, message, details) { | ||
const error = new SearchServiceError(errorType, message, details); | ||
const result = new Result(undefined, error); | ||
return result; | ||
} | ||
} | ||
//# sourceMappingURL=default-search-backend.js.map |
export declare enum SearchServiceErrorType { | ||
networkError = 0, | ||
itemNotFound = 1, | ||
decodingError = 2 | ||
decodingError = 2, | ||
searchEngineError = 3 | ||
} | ||
export declare class SearchServiceError extends Error { | ||
type: SearchServiceErrorType; | ||
constructor(type: SearchServiceErrorType, message?: string); | ||
details?: any; | ||
constructor(type: SearchServiceErrorType, message?: string, details?: any); | ||
} |
@@ -6,9 +6,12 @@ export var SearchServiceErrorType; | ||
SearchServiceErrorType[SearchServiceErrorType["decodingError"] = 2] = "decodingError"; | ||
SearchServiceErrorType[SearchServiceErrorType["searchEngineError"] = 3] = "searchEngineError"; | ||
})(SearchServiceErrorType || (SearchServiceErrorType = {})); | ||
export class SearchServiceError extends Error { | ||
constructor(type, message) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
constructor(type, message, details) { | ||
super(message); | ||
this.type = type; | ||
this.details = details; | ||
} | ||
} | ||
//# sourceMappingURL=search-service-error.js.map |
{ | ||
"name": "@internetarchive/search-service", | ||
"version": "0.0.1-alpha.15", | ||
"version": "0.0.1-alpha.16", | ||
"description": "A search service for the Internet Archive", | ||
@@ -5,0 +5,0 @@ "license": "AGPL-3.0-only", |
@@ -8,2 +8,5 @@ import { | ||
/** | ||
* A Byte is a unit-specific `number`, in bytes. | ||
*/ | ||
export type Byte = number; | ||
@@ -10,0 +13,0 @@ |
@@ -45,8 +45,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const message = err instanceof Error ? err.message : err; | ||
const error = new SearchServiceError( | ||
SearchServiceErrorType.networkError, | ||
message | ||
); | ||
const result = new Result<any, SearchServiceError>(undefined, error); | ||
return result; | ||
return this.getErrorResult(SearchServiceErrorType.networkError, message); | ||
} | ||
@@ -57,14 +52,31 @@ | ||
const json = await response.json(); | ||
const result = new Result<any, SearchServiceError>(json); | ||
return result; | ||
// the advanced search endpoint doesn't return an HTTP Error 400 | ||
// and instead returns an HTTP 200 with an `error` key in the payload | ||
const error = json['error']; | ||
if (error) { | ||
const forensics = json['forensics']; | ||
return this.getErrorResult( | ||
SearchServiceErrorType.searchEngineError, | ||
error, | ||
forensics | ||
); | ||
} else { | ||
// success | ||
return new Result<any, SearchServiceError>(json, undefined); | ||
} | ||
} catch (err) { | ||
const message = err instanceof Error ? err.message : err; | ||
const error = new SearchServiceError( | ||
SearchServiceErrorType.decodingError, | ||
message | ||
); | ||
const result = new Result<any, SearchServiceError>(undefined, error); | ||
return result; | ||
return this.getErrorResult(SearchServiceErrorType.decodingError, message); | ||
} | ||
} | ||
private getErrorResult( | ||
errorType: SearchServiceErrorType, | ||
message?: string, | ||
details?: any | ||
): Result<any, SearchServiceError> { | ||
const error = new SearchServiceError(errorType, message, details); | ||
const result = new Result<any, SearchServiceError>(undefined, error); | ||
return result; | ||
} | ||
} |
@@ -5,2 +5,3 @@ export enum SearchServiceErrorType { | ||
decodingError, | ||
searchEngineError, | ||
} | ||
@@ -11,6 +12,11 @@ | ||
constructor(type: SearchServiceErrorType, message?: string) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
details?: any; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
constructor(type: SearchServiceErrorType, message?: string, details?: any) { | ||
super(message); | ||
this.type = type; | ||
this.details = details; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
350217
4581