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

Exception updating inventory items #13

Closed
stephanstapel opened this issue Mar 21, 2023 · 7 comments · Fixed by #14
Closed

Exception updating inventory items #13

stephanstapel opened this issue Mar 21, 2023 · 7 comments · Fixed by #14

Comments

@stephanstapel
Copy link
Contributor

stephanstapel commented Mar 21, 2023

Hi,
did you ever come across this return code 400 when updating inventory items:

System.AggregateException: One or more errors occurred. (Received unexpected HTTP status code for request 'PUT'
https://api.bricklink.com/api/store/v1/inventories/331747049:
Expected = 200, received = 400.
Description: A request has been made with a malformed JSON body., message: INVALID_REQUEST_BODY.)
 ---> BricklinkSharp.Client.BricklinkHttpErrorException: Received unexpected HTTP status code for request 'PUT' https://api.bricklink.com
/api/store/v1/inventories/331747049:
Expected = 200, received = 400.
Description: A request has been made with a malformed JSON body., message: INVALID_REQUEST_BODY.
   at BricklinkSharp.Client.Extensions.JsonExtensions.GetData(JsonDocument document, Int32 expectedCode, String url, HttpMethod httpMethod)
   at BricklinkSharp.Client.Extensions.HttpClientExtensions.ParseResponse[TData](String responseBody, Int32 expectedCode, String url, HttpMethod httpMethod)
   at BricklinkSharp.Client.Extensions.HttpClientExtensions.ExecuteReadResponseAsync[TResponse](HttpClient httpClient, HttpMethod method, String url, Int32 expectedCode, Object body, JsonSerializerOptions jsonSerializerOptions, CancellationToken cancellationToken)
   at BricklinkSharp.Client.BricklinkClient.UpdateInventoryAsync(Int32 inventoryId, UpdateInventory updateInventory, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()

The JSON object looks like this:

{"quantity":"unit_price":0.6000,"description":null,"remarks":"SPC.0015","bulk":null,"is_retain":null,"is_stock_room":false,"stock_room_id":null,"my_cost":null,"sale_rate":null,"tier_quantity1":null,"tier_quantity2":null,"tier_quantity3":null,"tier_price1":null,"tier_price2":null,"tier_price3":null}

I found it. quantity is empty!

With the quantity being optional:

grafik

could this be the problem:

grafik

@gebirgslok
Copy link
Owner

Oha,
Good Catch @stephanstapel. That check for 0 (value) messes Up the json serialization. Instead, the converter should write "+0". The Check for null ist fine because null properties are ignored when writing anyway

Are there any other other custom json converters that might be affected by a similiar Bug?

Are willing to submit a PR?

Thanks and BR
Jens

@gebirgslok
Copy link
Owner

The converter has another issue. If the changedQuantity is negative, it should write a minus sign ( e.g. "-5"), according to https://www.bricklink.com/v3/api.page?page=update-inventory

@stephanstapel
Copy link
Contributor Author

Oha, Good Catch @stephanstapel. That check for 0 (value) messes Up the json serialization. Instead, the converter should write "+0". The Check for null ist fine because null properties are ignored when writing anyway

Are there any other other custom json converters that might be affected by a similiar Bug?

Are willing to submit a PR?

Thanks and BR Jens

the rest looks good. Just a small doubt in NullableItemTypeStringConverter and ItemTypeStringConverter here:

grafik

is it correct to return 0 (Minifig) as a default?

@stephanstapel
Copy link
Contributor Author

The converter has another issue. If the changedQuantity is negative, it should write a minus sign ( e.g. "-5"), according to https://www.bricklink.com/v3/api.page?page=update-inventory

that should come automatically I guess :)

@gebirgslok
Copy link
Owner

Lol, indeed. 😄

@gebirgslok
Copy link
Owner

Oha, Good Catch @stephanstapel. That check for 0 (value) messes Up the json serialization. Instead, the converter should write "+0". The Check for null ist fine because null properties are ignored when writing anyway
Are there any other other custom json converters that might be affected by a similiar Bug?
Are willing to submit a PR?
Thanks and BR Jens

the rest looks good. Just a small doubt in NullableItemTypeStringConverter and ItemTypeStringConverter here:

grafik

is it correct to return 0 (Minifig) as a default?

Not really, maybe it's better to throw in Case the parse fails?

@stephanstapel
Copy link
Contributor Author

Oha, Good Catch @stephanstapel. That check for 0 (value) messes Up the json serialization. Instead, the converter should write "+0". The Check for null ist fine because null properties are ignored when writing anyway
Are there any other other custom json converters that might be affected by a similiar Bug?
Are willing to submit a PR?
Thanks and BR Jens

the rest looks good. Just a small doubt in NullableItemTypeStringConverter and ItemTypeStringConverter here:
grafik
is it correct to return 0 (Minifig) as a default?

Not really, maybe it's better to throw in Case the parse fails?

yap, could you do this? I guess you know more about the base idea of your library. In my libraries, I usually add an Unknown value to all enums and leave it for the user to handle this. A bit unfair to be honest :)

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

Successfully merging a pull request may close this issue.

2 participants