This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
73 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,46 @@ | ||
/* eslint-disable max-classes-per-file */ | ||
export class MWSError extends Error { | ||
constructor(...parameters: string[]) { | ||
// Propagate some vendor-specific arguments | ||
super(...parameters) | ||
|
||
// If someone downlevels the compilation target to es5 | ||
Object.setPrototypeOf(this, MWSError.prototype) | ||
|
||
// Maintains proper stack trace (only available on V8) | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, MWSError) | ||
} | ||
} | ||
} | ||
import { Codec, GetInterface, optional, string } from 'purify-ts/Codec' | ||
import { ExtendableError } from 'ts-error' | ||
|
||
export class HttpError extends MWSError { | ||
public message = 'MWS: Encountered an error while sending a request: ' | ||
export class MWSError extends ExtendableError {} | ||
|
||
constructor(public error: Error, ...parameters: string[]) { | ||
super(...parameters) | ||
this.message += error.message | ||
Object.setPrototypeOf(this, HttpError.prototype) | ||
export class HttpError extends MWSError { | ||
public type!: string | ||
|
||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, HttpError) | ||
} | ||
} | ||
} | ||
public code!: string | ||
|
||
export class ParsingError extends MWSError { | ||
public message = 'MWS: Encountered an error while parsing a response: ' | ||
public detail!: string | undefined | ||
|
||
constructor(public error: string, ...parameters: string[]) { | ||
super(...parameters) | ||
this.message += error | ||
Object.setPrototypeOf(this, ParsingError.prototype) | ||
public mwsMessage!: string | ||
|
||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, ParsingError) | ||
} | ||
} | ||
public requestId!: string | ||
} | ||
|
||
export class ParsingError extends MWSError {} | ||
/* eslint-enable max-classes-per-file */ | ||
|
||
export const MWSApiError = Codec.interface({ | ||
ErrorResponse: Codec.interface({ | ||
Error: Codec.interface({ | ||
Type: string, | ||
Code: string, | ||
Message: string, | ||
Detail: optional(string), | ||
}), | ||
RequestId: string, | ||
}), | ||
}) | ||
|
||
type MWSApiError = GetInterface<typeof MWSApiError> | ||
|
||
/* eslint-disable no-param-reassign */ | ||
export const enhanceError = (error: HttpError, response: MWSApiError): HttpError => { | ||
error.type = response.ErrorResponse.Error.Type | ||
error.code = response.ErrorResponse.Error.Code | ||
error.detail = response.ErrorResponse.Error.Detail | ||
error.mwsMessage = response.ErrorResponse.Error.Message | ||
error.requestId = response.ErrorResponse.RequestId | ||
|
||
return error | ||
} | ||
/* eslint-enable no-param-reassign */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<ErrorResponse xmlns="https://mws.amazonservices.com/Orders/2013-09-01">\n' + | ||
<Error> | ||
<Type>Sender</Type> | ||
<Code>InvalidParameterValue</Code> | ||
<Message>CreatedAfter or LastUpdatedAfter must be specified</Message> | ||
</Error> | ||
<RequestId>e26147f9-30cc-4379-9fb5-bd4ad966c48b</RequestId> | ||
</ErrorResponse> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters