Skip to content

Commit

Permalink
Handle empty media stream config
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Jan 24, 2025
1 parent 7529370 commit c937f72
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/api.test/Mocks/IsarServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<IsarMission> StartMoveArm(Robot robot, string position)
return isarServiceMissionResponse;
}

public async Task<MediaConfig> GetMediaStreamConfig(Robot robot)
public async Task<MediaConfig?> GetMediaStreamConfig(Robot robot)
{
await Task.Run(() => Thread.Sleep(1));
return new MediaConfig
Expand Down
2 changes: 1 addition & 1 deletion backend/api/Controllers/MediaStreamController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ IRobotService robotService
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<MediaConfig>> GetMediaStreamConfig([FromRoute] string id)
public async Task<ActionResult<MediaConfig?>> GetMediaStreamConfig([FromRoute] string id)
{
try
{
Expand Down
14 changes: 8 additions & 6 deletions backend/api/Services/IsarService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IIsarService

public Task<IsarMission> StartMoveArm(Robot robot, string armPosition);

public Task<MediaConfig> GetMediaStreamConfig(Robot robot);
public Task<MediaConfig?> GetMediaStreamConfig(Robot robot);
}

public class IsarService(
Expand Down Expand Up @@ -305,7 +305,7 @@ HttpResponseMessage response
return (description, (int)statusCode);
}

public async Task<MediaConfig> GetMediaStreamConfig(Robot robot)
public async Task<MediaConfig?> GetMediaStreamConfig(Robot robot)
{
string mediaStreamPath = $"/media/media-stream-config";
var response = await CallApi(HttpMethod.Get, robot.IsarUri, mediaStreamPath);
Expand All @@ -317,11 +317,13 @@ public async Task<MediaConfig> GetMediaStreamConfig(Robot robot)
logger.LogError("{Message}: {ErrorResponse}", message, errorResponse);
throw new ConfigException(message);
}
if (response.Content is null)

if (response.StatusCode == HttpStatusCode.NoContent)
{
string errorMessage = "Could not read content from new robot media stream config";
logger.LogError("{ErrorMessage}", errorMessage);
throw new ConfigException(errorMessage);
logger.LogDebug(
$"Robot with id {robot.Id} did not return any content for media stream config. This is likely because the robot doesn't have a media stream."
);
return null;
}

IsarMediaConfigMessage? isarMediaConfigResponse;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/ApiCaller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class BackendAPICaller {
return result.content
}

static async getRobotMediaConfig(robotId: string): Promise<MediaStreamConfig> {
static async getRobotMediaConfig(robotId: string): Promise<MediaStreamConfig | null | undefined> {
const path: string = 'media-stream/' + robotId
const result = await this.GET<MediaStreamConfig>(path).catch(BackendAPICaller.handleError('GET', path))
return result.content
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/Contexts/MediaStreamContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ export const MediaStreamProvider: FC<Props> = ({ children }) => {

const refreshRobotMediaConfig = (robotId: string) => {
BackendAPICaller.getRobotMediaConfig(robotId)
.then((conf: MediaStreamConfig) => addConfigToMediaStreams(conf))
.then((conf: MediaStreamConfig | null | undefined) => {
if (conf) addConfigToMediaStreams(conf)
})
.catch((e) => console.error(e))
}

Expand Down

0 comments on commit c937f72

Please sign in to comment.