Skip to content

Commit 593db7e

Browse files
committed
Add file_path to MediaFileNotFound error
1 parent 93fa48f commit 593db7e

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

native/kotlin/api/kotlin/src/main/kotlin/rs/wordpress/api/kotlin/WpApiClient.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ constructor(
4242
statusCode = exception.statusCode,
4343
reason = exception.reason
4444
)
45-
is WpApiException.MediaFileNotFound -> WpRequestResult.MediaFileNotFound()
45+
is WpApiException.MediaFileNotFound -> WpRequestResult.MediaFileNotFound(
46+
filePath = exception.filePath
47+
)
4648
is WpApiException.ResponseParsingException -> WpRequestResult.ResponseParsingError(
4749
reason = exception.reason,
4850
response = exception.response,

native/kotlin/api/kotlin/src/main/kotlin/rs/wordpress/api/kotlin/WpRequestExecutor.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ class WpRequestExecutor(
5252
mediaUploadRequest.mediaParams().forEach { (k, v) ->
5353
multipartBodyBuilder.addFormDataPart(k, v)
5454
}
55+
val filePath = mediaUploadRequest.filePath()
5556
val file =
56-
WpRequestExecutor::class.java.classLoader?.getResource(mediaUploadRequest.filePath())?.file?.let {
57+
WpRequestExecutor::class.java.classLoader?.getResource(filePath)?.file?.let {
5758
File(
5859
it
5960
)
60-
} ?: throw MediaUploadRequestExecutionException.MediaFileNotFound()
61+
} ?: throw MediaUploadRequestExecutionException.MediaFileNotFound(filePath)
6162
multipartBodyBuilder.addFormDataPart(
6263
name = "file",
6364
filename = file.name,

native/kotlin/api/kotlin/src/main/kotlin/rs/wordpress/api/kotlin/WpRequestResult.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ sealed class WpRequestResult<T> {
2020
val reason: String,
2121
) : WpRequestResult<T>()
2222

23-
class MediaFileNotFound<T> : WpRequestResult<T>()
23+
class MediaFileNotFound<T>(
24+
val filePath: String
25+
) : WpRequestResult<T>()
2426

2527
class SiteUrlParsingError<T>(
2628
val reason: String,

wp_api/src/api_error.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ pub enum WpApiError {
2323
status_code: Option<u16>,
2424
reason: String,
2525
},
26-
#[error("Media file not found")]
27-
MediaFileNotFound,
26+
#[error("Media file not found at file path: {}", file_path)]
27+
MediaFileNotFound { file_path: String },
2828
#[error("Error while parsing. \nReason: {}\nResponse: {}", reason, response)]
2929
ResponseParsingError { reason: String, response: String },
3030
#[error("Error while parsing site url: {}", reason)]
@@ -333,8 +333,8 @@ pub enum MediaUploadRequestExecutionError {
333333
status_code: Option<u16>,
334334
reason: String,
335335
},
336-
#[error("Media file not found")]
337-
MediaFileNotFound,
336+
#[error("Media file not found at file path: {}", file_path)]
337+
MediaFileNotFound { file_path: String },
338338
}
339339

340340
impl From<RequestExecutionError> for WpApiError {
@@ -361,7 +361,9 @@ impl From<MediaUploadRequestExecutionError> for WpApiError {
361361
status_code,
362362
reason,
363363
},
364-
MediaUploadRequestExecutionError::MediaFileNotFound => Self::MediaFileNotFound,
364+
MediaUploadRequestExecutionError::MediaFileNotFound { file_path } => {
365+
Self::MediaFileNotFound { file_path }
366+
}
365367
}
366368
}
367369
}

0 commit comments

Comments
 (0)