C
C#2mo ago
SylveonDeko

Im getting a very ambiguous error when trying to get data via aspnet

the error;
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"model": [
"The model field is required."
]
},
"traceId": "00-553b2b7da84c52f6ab86d008eb76943f-adb629679e4bd9de-00"
}
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"model": [
"The model field is required."
]
},
"traceId": "00-553b2b7da84c52f6ab86d008eb76943f-adb629679e4bd9de-00"
}
The code:
/// <summary>
/// Updates a guild config from the provided json and guildid
/// </summary>
/// <param name="guildId">The guildid to update a config for</param>
/// <param name="model">The json body of the model to update</param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> UpdateGuildConfig(ulong guildId, [FromBody] GuildConfig model)
{
try
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
await service.UpdateGuildConfig(guildId, model);
return Ok();
}
catch (Exception e)
{
Log.Error(e, "Error updating guild config");
return StatusCode(500);
}
}
}
/// <summary>
/// Updates a guild config from the provided json and guildid
/// </summary>
/// <param name="guildId">The guildid to update a config for</param>
/// <param name="model">The json body of the model to update</param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> UpdateGuildConfig(ulong guildId, [FromBody] GuildConfig model)
{
try
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
await service.UpdateGuildConfig(guildId, model);
return Ok();
}
catch (Exception e)
{
Log.Error(e, "Error updating guild config");
return StatusCode(500);
}
}
}
79 Replies
SylveonDeko
SylveonDeko2mo ago
The json im sending as the body https://paste.mod.gg/dnngsmodvzpw/0
BlazeBin - dnngsmodvzpw
A tool for sharing your source code with the world!
SylveonDeko
SylveonDeko2mo ago
:foxexited:
unhAPI
unhAPI2mo ago
what a beefy json maybe the error is in the sender, not in the receiver
SylveonDeko
SylveonDeko2mo ago
which is what im trying to find out im actually gonnago insane
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"message": [
"The message field is required."
]
},
"traceId": "00-f5d127fc6a00e0cd28fe148c883461a5-aba989072b5d28e9-00"
}
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"message": [
"The message field is required."
]
},
"traceId": "00-f5d127fc6a00e0cd28fe148c883461a5-aba989072b5d28e9-00"
}
SylveonDeko
SylveonDeko2mo ago
No description
unhAPI
unhAPI2mo ago
well, that's fair, it's not valid json also, where is guildId configured
[HttpPost] public async Task<IActionResult> UpdateGuildConfig(ulong guildId, [FromBody] GuildConfig model)
like, the route
SylveonDeko
SylveonDeko2mo ago
At the controller class I’ve tried with valid json too
unhAPI
unhAPI2mo ago
what do you mean, you've put this in parameter in the routing attribute of the class itself?
SylveonDeko
SylveonDeko2mo ago
Correct Also I solved this, at least for afk, somehow removing the required attribute fixed it
unhAPI
unhAPI2mo ago
yes, removing required "fixes" it but uhm i was sure i wrote another message what is happening was it another thread? i remember saying that some tests could be useful
SylveonDeko
SylveonDeko2mo ago
this issue has reappeared but this time it doesnt even make sense the response i send:
"test"
"test"
The controller code:
/// <summary>
/// Remove a dpo
/// </summary>
/// <param name="guildId"></param>
/// <param name="commandName"></param>
/// <returns></returns>
[HttpDelete("dpo/{guildId}")]
public async Task<IActionResult> RemoveDpo(ulong guildId, [FromBody] string commandName)
{
var com = cmdServ.Search(commandName);
if (!com.IsSuccess)
return BadRequest(com);
await dpoService.RemoveOverride(guildId, commandName);
return Ok();
}
/// <summary>
/// Remove a dpo
/// </summary>
/// <param name="guildId"></param>
/// <param name="commandName"></param>
/// <returns></returns>
[HttpDelete("dpo/{guildId}")]
public async Task<IActionResult> RemoveDpo(ulong guildId, [FromBody] string commandName)
{
var com = cmdServ.Search(commandName);
if (!com.IsSuccess)
return BadRequest(com);
await dpoService.RemoveOverride(guildId, commandName);
return Ok();
}
The response:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"commandName": [
"The commandName field is required."
]
},
"traceId": "00-b90dcda822a05ec97c546c28d360e4ec-3cd9035000a26306-00"
}
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$": [
"The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
],
"commandName": [
"The commandName field is required."
]
},
"traceId": "00-b90dcda822a05ec97c546c28d360e4ec-3cd9035000a26306-00"
}
I am actually going to go insane and yes, i have tried doing {"commandName": "test"} too
Angius
Angius2mo ago
How are you sending that data? Does it work when sending with Swagger or some API client like Bruno or Insomnium?
SylveonDeko
SylveonDeko2mo ago
Tried with postman and swagger, no go That’s why im stumped, I would expect at least swagger to be able to do it
Angius
Angius2mo ago
Try wrapping the parameter into a record or something?
SylveonDeko
SylveonDeko2mo ago
Tried that, then it says it requires that, even if I provide the correct json for it
Want results from more Discord servers?
Add your server