Skip to content

Commit

Permalink
chore: setup detekt (#30)
Browse files Browse the repository at this point in the history
* chore: setup detekt

* fix: magic number
  • Loading branch information
adrielcafe authored Oct 21, 2019
1 parent 9c2dc64 commit 819582e
Show file tree
Hide file tree
Showing 13 changed files with 631 additions and 23 deletions.
1 change: 0 additions & 1 deletion android-module.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "org.jlleitschuh.gradle.ktlint"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.jcaique.dialetus

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
3 changes: 1 addition & 2 deletions app/src/test/java/com/jcaique/dialetus/ExampleUnitTest.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.jcaique.dialetus

import org.junit.Assert.assertEquals
import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
Expand Down
16 changes: 11 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
buildscript {

repositories {
mavenLocal()
google()
jcenter()
mavenLocal()
maven { url 'https://kotlin.bintray.com/kotlinx' }
maven { url 'https://jitpack.io' }
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://dl.bintray.com/android/android-tools' }
maven { url 'https://plugins.gradle.org/m2/' }
jcenter()
}

dependencies {
classpath BuildPlugins.androidGradlePlugin
classpath BuildPlugins.kotlinGradlePlugin
classpath BuildPlugins.kotlinxSerializiationPlugin
classpath BuildPlugins.ktlint
classpath BuildPlugins.detekt
}
}

allprojects {
apply plugin: 'org.jlleitschuh.gradle.ktlint'
apply plugin: 'io.gitlab.arturbosch.detekt'

repositories {
mavenLocal()
google()
jcenter()

mavenLocal()
maven { url "https://kotlin.bintray.com/kotlinx" }

maven { url 'https://jitpack.io' }
}

detekt {
config = files("${rootDir}/detekt.yml")
}

configurations.all {
resolutionStrategy {
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/java/dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ object Versions {
const val androidGradleSupport = "3.5.1"
const val gmsSupport = "4.3.2"
const val ktlint = "9.0.0"
const val detekt = "1.1.1"

const val okhttp4 = "4.2.1"
const val retrofit2 = "2.6.2"
Expand Down Expand Up @@ -95,6 +96,7 @@ object BuildPlugins {
val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
val kotlinxSerializiationPlugin = "org.jetbrains.kotlin:kotlin-serialization:${Versions.kotlin}"
val ktlint = "org.jlleitschuh.gradle:ktlint-gradle:${Versions.ktlint}"
val detekt = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${Versions.detekt}"

val gmsPlugin = "com.google.gms:google-services:${Versions.gmsSupport}"
val firebaseCrashlytics = "io.fabric.tools:gradle:${Versions.fabric}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ package com.jcaique.data.networking
import com.jcaique.domain.errors.ErrorTransformer
import com.jcaique.domain.errors.GatewayIntegrationIssues
import retrofit2.HttpException
import java.net.HttpURLConnection.HTTP_BAD_REQUEST
import java.net.HttpURLConnection.HTTP_NOT_FOUND

internal object HttpErrorHandler : ErrorTransformer {

private const val HTTP_CLIENT_CLOSED_REQUEST = 499

override suspend fun transform(incoming: Throwable): Throwable = when (incoming) {
is HttpException -> handleHttpError(incoming.code())
else -> incoming
}

private fun handleHttpError(code: Int): Throwable = when (code) {
404 -> GatewayIntegrationIssues.NotFound
in 400..499 -> GatewayIntegrationIssues.ClientIssue
HTTP_NOT_FOUND -> GatewayIntegrationIssues.NotFound
in HTTP_BAD_REQUEST..HTTP_CLIENT_CLOSED_REQUEST -> GatewayIntegrationIssues.ClientIssue
else -> GatewayIntegrationIssues.ServerIssue
}
}
Loading

0 comments on commit 819582e

Please sign in to comment.