Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error handling documentation. #185

Open
nrathi opened this issue Dec 19, 2024 · 12 comments
Open

Update error handling documentation. #185

nrathi opened this issue Dec 19, 2024 · 12 comments
Assignees

Comments

@nrathi
Copy link

nrathi commented Dec 19, 2024

I upgraded to 9.1.1 for an auth token fix, but saw that errors are handled differently now. I read through the documentation but it's not matching what I'm seeing in practice (for the Trading API).

The docs say:

try {
  const result = await eBay.trading.GetItem({
    ItemID: 'itemId',
  });
  console.log(result);
} catch (error) {
  ...
  // in error there is also the field "meta" with the response
  if (error instanceof EBayApiError && error.meta?.res?.status === 404) {
    // not found
    
    // The first error
    console.log(error?.firstError);
  }
}

In practice, what I'm seeing is:

If there are no errors with SeverityCode "Error" (as opposed to "Warning")
=> Then error.meta is EBayTraditionalErrorResponse & ExpectedResponseType

If there is an error with SeverityCode "Error"
=> Then error.meta is EBayTraditionalErrorResponse

Furthermore, I am not seeing res as a field on error.meta

So for example, if you call api.trading.UploadSiteHostedPictures with an expected response type of IUploadPictureResponse and the pictures aren't high quality (warning, not error)
Then the function will throw, and error.Errors will have the relevant warning
And error.meta will be of the type EBayTraditionalErrorResponse & ExpectedResponseType

Here's an example response:

Timestamp: '2024-12-19T04:57:03.299Z',
Ack: 'Warning',
Errors: {
  ShortMessage: 'Quality value of the JPEG format picture you uploaded is lower than recommended.',
  LongMessage: 'To reduce possible issues with picture display quality, eBay recommends that pictures you upload have a JPEG quality value of 90 or greater.',
  ErrorCode: 21916791,
  SeverityCode: 'Warning',
  ErrorParameters: { Value: 90, ParamID: 0 },
  ErrorClassification: 'RequestError'
},
Version: 0,
Build: 'mediasvcs-5.0.34_20241119152902605',
PictureSystemVersion: 2,
SiteHostedPictureDetails: {
  PictureSet: 'Standard',
  PictureFormat: 'JPG',
  FullURL: 'https://i.ebayimg.com/00/s/MTAwMFgxMDAw/z/lWkAAOSw6eZnY6ef/$_1.JPG?set_id=2',
  BaseURL: 'https://i.ebayimg.com/00/s/MTAwMFgxMDAw/z/lWkAAOSw6eZnY6ef/$_',
  PictureSetMember: {
    MemberURL: 'https://i.ebayimg.com/00/s/MTAwMFgxMDAw/z/lWkAAOSw6eZnY6ef/$_1.JPG',
    PictureHeight: 400,
    PictureWidth: 400
  },
  UseByDate: '2025-01-18T04:57:03.169Z'
},
req: {...},
// There is no res

Hopefully that makes sense.

@dantio
Copy link
Collaborator

dantio commented Dec 19, 2024

@nrathi
Thank you for reporting.
The warning should not be handled as an Error. I'll have a look on this issue.

@nrathi
Copy link
Author

nrathi commented Dec 19, 2024

Ah, thanks, that makes a lot more sense. I didn't understand why UploadSiteHostedPictures was throwing an error all of a sudden, especially when the "error" was just a warning.

It looks like this is happening for addFixedPriceItem, too, so I'll assume it's happening across the board and add a temporary wrapper around all the endpoints ignoring only-warnings.

async function wrapTradingApiCall<T>(apiCall: () => Promise<T>): Promise<T> {
  try {
    return await apiCall();
  } catch (e) {
    if (e instanceof EBayError && isTraditionalErrorResponse(e.meta)) {
      const errors = convertToArray(e.meta.Errors);
      // If all errors are warnings, return the successful response from meta
      if (errors.every((error) => error.SeverityCode === "Warning")) {
        const response = e.meta as unknown as T;
        if (response != null) {
          return response;
        }
      }
    }
    throw e;
  }
}

@nrathi
Copy link
Author

nrathi commented Dec 19, 2024

Do you just need to update this function:

export const checkEBayTraditionalResponse = (apiResponse: any, data: any) => {

To check if all the "errors" are actually warnings?

@dantio
Copy link
Collaborator

dantio commented Dec 19, 2024

Yes, it's the function. I'll git blame and check why the warning is treated as error. I think it was a feature request...

@nrathi
Copy link
Author

nrathi commented Dec 19, 2024

Is it the "firstError" feature request?

Would you be open to creating a new 8.x.x release with the auth token fix? I am nervous about adding this wrapper to my entire integration.

@dantio
Copy link
Collaborator

dantio commented Dec 19, 2024

I would rather fix the "Warning" as "Error" treatment. I'll do an indeep investigation and testing and come back to you.

@nrathi
Copy link
Author

nrathi commented Dec 19, 2024

Sounds good, keep me posted. In the worst case, can you confirm this looks safe to wrap all my calls with?

async function wrapTradingApiCall<T>(apiCall: () => Promise<T>): Promise<T> {
  try {
    return await apiCall();
  } catch (e) {
    if (e instanceof EBayError && isTraditionalErrorResponse(e.meta)) {
      const errors = convertToArray(e.meta.Errors);
      // If all errors are warnings, return the successful response from meta
      if (errors.every((error) => error.SeverityCode === "Warning")) {
        const response = e.meta as unknown as T;
        if (response != null) {
          return response;
        }
      }
    }
    throw e;
  }
}```

@nrathi
Copy link
Author

nrathi commented Dec 20, 2024

Hey, any update? Sorry to be a pain. Just started hitting this auth issue as I mentioned, so want to get a fix out ASAP.

@dantio
Copy link
Collaborator

dantio commented Dec 20, 2024

Hey Ill have time tomorrow

@dantio dantio closed this as completed in a1e939a Dec 20, 2024
@dantio dantio reopened this Dec 20, 2024
@dantio
Copy link
Collaborator

dantio commented Dec 20, 2024

I dig through the changes and the check for the "Failure" was mistakenly removed.
I have added the check back:

if ('Errors' in data && data.Ack !== 'Failure') {

RC

@dantio
Copy link
Collaborator

dantio commented Jan 2, 2025

@nrathi
Have you already tried the RC version?

@nrathi
Copy link
Author

nrathi commented Jan 2, 2025

Yes, I took the update as soon as it came out! No issues on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants