Design - prevent multiple nesting in function I have a function written in Groovy which needs to save a record and also return response from the server.
Function is working fine, but I am not happy with the design because I have a problem with multiple nesting.

This is the function:

Map scanAccessRecord(GrailsParameterMap params){

    Map response
    Date currentTime = new Date()
    String readerEthernetAddress = params.readerMac
    Reader reader = Reader.findByDeletedAndEthernetAddress(false, readerEthernetAddress)
    Boolean isAccessIn = (params.isAccessIn == "True")

    if(reader)
    {
        UserSettings userSettings = UserSettings.findByRfidCode(params.rfid.toString())

        if(userSettings)
        {
            if(userSettings.user.company.id == reader.companyId)
            {
                AccessRecord accessRecord = new AccessRecord(reader:reader, userId:userSettings.userId, specificDate:currentTime, isAccessIn: isAccessIn)

                if(accessRecord.save(flush: true))
                {
                    response = [
                            status: '00',
                            message: 'OK',
                            recordId: accessRecord.id,
                    ]
                }
                else
                {
                    response = [
                            status: '60',
                            message: 'error'
                    ]
                }
            }
            else
            {
                response = [status: '40', message: 'USER AND READER ARE NOT FROM SAME COMPANY']
            }
        }
        else
        {
            response = [status: '10', message: 'UNKNOWN USER']
        }
    }
    else
    {
        response = [status: '50', message: 'READER NOT FOUND']
    }

    return response
}


What can I do to make this function "cleaner"?
Use optional instead of null. I wrote an article about avoiding nulls if you are interested.  
Use early returns to avoid nesting


If !reader return [status: '50', message: 'READER NOT FOUND']

If !userSettings return...
Rest of the logic



I prefer to avoid nulls,so I would choose to call save with failOnError=true and it will throw exception instead of returning null when save fails. 
I assume  you want any exception to return [ status: '60', message: 'error'], if you use save with failOnError=true then the error is handled in one place only. 
add validation for params.isAccessIn. If by mistake it is nor true or false, it is better to throw error than do something the client didn't intend to. 
Maybe you should be more flexible with params.isAccessIn and compare strings without case sensitivity.